var $, element, layer, laydate, form;
var today = DateUtils.dateFormat(new Date(), "yyyy-MM-dd"); // 今天的日期
var uploadfiles = new Array(); // 要上传的文件列表路径
var tips = false;   // 合同信息生成明细修改提示状态
var unit = 0;   // 单位
var unitHtml = "元/㎡·天";     // 单位默认显示的文字
var ftype = 1;  // 支付按月还是按日 0按日 1按月
var wtype = 1;  // 水费选择默认价格还是自定义 0默认 1自定义
var etype = 1;  // 电费选择默认价格还是自定义 0默认 1自定义

var roomType = "0"; // 选中的项目类型 0自有 1非自有

var chooseIdArray = new Array(); // 选中的ID数组
var chooseItemArray = new Array(); // 选中的项目数组
var chooseOnOff = false;    // 选择房源项目框状态
var collection = false;    // 代收开关

/**
 * 通过房间详情点击的新增合同时
 * 获取当前选中的房间ID
 */
var roomId = QueryUtils.GetQueryString("ROOM_ID");

/* 新增修改类型 */
var addType = QueryUtils.GetQueryString("TYPE");
/* 合同ID */
var contractId = QueryUtils.GetQueryString("CONTRACT_ID");

layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'upload'], function () {
    // 加载元素控件
    $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form;
    var upload = layui.upload;

    /*//多图片上传
    upload.render({
        elem: '#upload'
        ,url: '/upload/uploadImgs'
        ,multiple: true
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#imgList').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
            });
        }
        ,done: function(res){
            //上传完毕
            console.log(res);
        }
    });*/

    //多文件列表示例
    var files;
    var demoListView = $('#demoList')
        , uploadListIns = upload.render({
        elem: '#testList'
        , url: '/servlet/UploadHandleServlet'
        // ,accept: 'file'
        , multiple: true
        , auto: false
        , bindAction: '#testListAction'
        , choose: function (obj) {
            files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    , '<td><img src="' + result + '" alt="' + file.name + '" class="layui-upload-img"></td>'
                    , '<td>' + file.name + '</td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td>等待上传</td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                    return false;
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();
                });

                demoListView.append(tr);
            });
        }
        , done: function (res, index, upload) {
            if (res.errcode == 0) { //上传成功
                var obj = {};
                obj.name = res.data.fileName;
                obj.size = res.data.fileSize;
                obj.ext = res.data.extName;
                obj.url = res.data.fileUrl;
                uploadfiles.push(obj);
                var tr = demoListView.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
                tds.eq(4).html(''); //清空操作
                delete files[index]; //删除文件队列已经上传成功的文件
                return;
            }
            this.error(index, upload);
        }
        , error: function (index, upload) {
            var tr = demoListView.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).html('<span style="color: #FF5722;">上传失败</span>');
            tds.eq(4).find('.demo-reload').removeClass('layui-hide'); //显示重传
        }
    });

    

    // 合同编号提示文字
    $('#contractNum').hover(function(){
        var that = this;
        layer.tips('合同编号规则：楼宇名称 年月日 - 每日中的第几份合同。如xx楼宇xx年xx月xx日-1', that, {
            tips: [1, '#FFB800'],
            anim: -1,
            isOutAnim: false,
            time: 0
        });
    }, function () {
        layer.closeAll('tips');
    });


    // 单位下拉框
    form.on('select(unit)', function (data) {
        unit = Number(data.value);
        switch (unit) {
            case 0:
                unitHtml = "元/㎡·天";
                break;
            case 1:
                unitHtml = "元/天";
                break;
            case 2:
                unitHtml = "元/月";
                break;
            case 3:
                unitHtml = "元/年";
                break;
            case 4:
                unitHtml = "元";
                break;
            case 5:
                unitHtml = "元/㎡·月";
                break;
        }
        $(".change-unit").html(unitHtml);
        change.znjChange();
    });

    // 递增率规则单选框事件
    form.on('radio(dzlx)', function (data) {
        change.rentOrdiscountOrIncreasingChange();
    });

    // 付款分配规则单选框事件
    form.on('radio(fkfp)', function (data) {
        if (data.value == 0) {
            $("input[name='unit-fkfp']").parent().parent().find(".input-label-title").html("发票占比：");
            $("input[name='unit-fkfp']").parent().find(".input-label-unit").html("%");
        } else if (data.value == 1) {
            $("input[name='unit-fkfp']").parent().parent().find(".input-label-title").html("发票金额：");
            $("input[name='unit-fkfp']").parent().find(".input-label-unit").html("元/期");
        }
    });

    // 支付月数按钮点击事件
    $(".payMonths-btns a").click(function (e) {
        $(this).addClass('layui-this').siblings().removeClass("layui-this");
        if ($(this).data("value") != "0") {
            ftype = $(this).data("value");
            $("input[name='payMonths']").parent().find(".input-label-unit").html("月");
            $("input[name='payMonths']").val($(this).data("value"));
        } else {
            ftype = 0;
            $("input[name='payMonths']").parent().find(".input-label-unit").html("日");
        }
    });

    // 租赁方式单选框点击事件
    form.on('radio(rent-type)', function (data) {
        if (data.value == "0") {
            $(".person-input").hide();
            $(".company-input").show();
        } else if (data.value == "1") {
            $(".company-input").hide();
            $(".person-input").show();
        }
    });

    // 付款日期下拉框
    form.on('select(fkrq)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("天");
        } else if (data.value == "1") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("日");
        }
    });

    // 账单中付款分配类型下拉框
    form.on('select(unit-fkfp)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("%");
            var je = $(this).parent().parent().parent().parent().find("input[name='edit-zzje']").val();
            var bl = $(this).parent().parent().parent().parent().find("input[name='unit-fkfp-num']").val();
            var value = Number(je) * Number(bl) / 100;
            $(this).parent().parent().parent().parent().find(".unit-kfpJe").html(value.toFixed(2));
        } else if (data.value == "1") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元");
            $(this).parent().parent().parent().parent().find(".unit-kfpJe").html("");
        }
    });

    // 物业费用类型选择框
    form.on('checkbox(extra)', function (data) {
        var val = data.value;
        var title = data.elem.title;
        var priceList;
        // 通过物业项ID获取该物业项的所有默认价格
        $.ajax({
            url: "/property/propertyPriceList",
            data: {PROPERTY_SET_ID: val},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    var data = res.data;
                    if (!!data) {
                        priceList = data;
                    }
                    form.render();
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
        if (data.elem.checked == true) {
            switch (val) {
                case "a14e6f2e190e4492badac72e9b42152e":
                    $(".w-default-price-list").empty();
                    if (!!priceList) {
                        for (var i = 0; i < priceList.length; i++) {
                            var str = '<input type="radio" name="w-unit-price" lay-filter="w-unit-price" value="' + priceList[i].ID + '" title="' + priceList[i].PRICE_NAME + '（' + priceList[i].PRICE_TYPE + '元/吨）' + '">';
                            $(".w-default-price-list").append(str);
                        }
                        form.render();
                    }
                    $(".water-content").show();
                    break;
                case "ddcf9b35bbe04cd88834e21c1fd74f32":
                    $(".e-default-price-list").empty();
                    if (!!priceList) {
                        for (var i = 0; i < priceList.length; i++) {
                            var str = '<input type="radio" name="e-unit-price" lay-filter="e-unit-price" value="' + priceList[i].ID + '" title="' + priceList[i].PRICE_NAME + '（' + priceList[i].PRICE_TYPE + '元/度）' + '">';
                            $(".e-default-price-list").append(str);
                        }
                        form.render();
                    }
                    $(".power-content").show();
                    break;
                default:
                    var sm = "";
                    var sd = "";
                    var em = "";
                    var ed = "";
                    if (val == "669791dac4894160bc8d79b484519e96") {
                        sm = "11";
                        sd = "15";
                        em = "3";
                        ed = "15";
                    } else if (val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                        sm = "5";
                        sd = "15";
                        em = "9";
                        ed = "15";
                    }
                    var jfzqStr = '<div class="layui-form-item">\n' +
                        '              <div class="layui-inline">\n' +
                        '                  <label class="layui-form-label">计费周期：</label>\n' +
                        '                  <div class="layui-input-inline">\n' +
                        '                      <input type="number" name="jfzqStartMonth" value="' + sm + '" autocomplete="off" class="layui-input">\n' +
                        '                      <span class="input-label-unit">月</span>\n' +
                        '                  </div>\n' +
                        '                  <div class="layui-input-inline">\n' +
                        '                      <input type="number" name="jfzqStartDay" value="' + sd + '" autocomplete="off" class="layui-input">\n' +
                        '                      <span class="input-label-unit">日</span>\n' +
                        '                  </div>\n' +
                        '                  <div class="layui-input-inline" style="width: 10px;">\n' +
                        '                      至\n' +
                        '                  </div>\n' +
                        '                  <div class="layui-input-inline">\n' +
                        '                      <input type="number" name="jfzqEndMonth" value="' + em + '" autocomplete="off" class="layui-input">\n' +
                        '                      <span class="input-label-unit">月</span>\n' +
                        '                  </div>\n' +
                        '                  <div class="layui-input-inline">\n' +
                        '                      <input type="number" name="jfzqEndDay" value="' + ed + '" autocomplete="off" class="layui-input">\n' +
                        '                      <span class="input-label-unit">日</span>\n' +
                        '                  </div>\n' +
                        '              </div>\n' +
                        '          </div>';
                    var str = '<div class="extra-content ' + val + '-content"  data-id="' + val + '">\n' +
                        '          <fieldset class="layui-elem-field">\n' +
                        '              <legend>' + title + '</legend>\n' +
                        '              <div class="layui-field-box">\n' +
                        '                  <div class="layui-form-item">\n' +
                        '                      <div class="layui-inline">\n' +
                        '                          <label class="layui-form-label">发票占比：</label>\n' +
                        '                          <div class="layui-input-inline">\n' +
                        '                              <input type="number" name="property-fpzb" lay-verify="" autocomplete="off" class="layui-input">\n' +
                        '                              <span class="input-label-unit">%</span>\n' +
                        '                          </div>\n' +
                        '                      </div>\n' +
                        '                  </div>';
                    if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                        str += jfzqStr;
                    } else {
                        str += '          <div class="layui-form-item">\n' +
                            '                      <div class="layui-inline">\n' +
                            '                          <label class="layui-form-label">付款周期：</label>\n' +
                            '                          <div class="layui-input-inline">\n' +
                            '                              <input type="number" name="payZhouQi" autocomplete="off" class="layui-input">\n' +
                            '                              <span class="input-label-unit">月</span>\n' +
                            '                          </div>\n' +
                            '                      </div>\n' +
                            '                  </div>\n';
                    }
                    str += '           <div class="layui-form-item">\n' +
                        '                      <div class="layui-inline">\n' +
                        '                          <label class="layui-form-label">收费日期：</label>\n' +
                        '                          <div class="layui-input-inline" style="height:25px;">\n' +
                        '                              <select name="sfrq" lay-filter="sfrq">\n' +
                        '                                  <option value="0" selected="">提前日收费</option>\n' +
                        '                                  <option value="1">固定日收费</option>\n' +
                        '                              </select>\n' +
                        '                          </div>\n' +
                        '                          <div class="layui-input-inline">\n' +
                        '                              <input type="number" name="payRiQi" autocomplete="off" class="layui-input">\n' +
                        '                              <span class="input-label-unit">天</span>\n' +
                        '                          </div>\n' +
                        '                      </div>\n' +
                        '                  </div>\n';
                    var sffsStr = '       <div class="layui-form-item">\n' +
                        '                       <div class="layui-inline">\n' +
                        '                           <label class="layui-form-label">收费方式：</label>\n' +
                        '                           <div class="layui-input-inline">\n' +
                        '                               <select name="sfje" lay-filter="sfje">\n' +
                        '                                   <option value="0" selected="">固定收费</option>\n' +
                        '                                   <option value="2">按面积收费</option>\n' +
                        '                               </select>\n' +
                        '                           </div>\n' +
                        /*'                           <div class="layui-input-inline">\n' +
                        '                               <input type="number" name="payJinE" autocomplete="off" class="layui-input">\n' +
                        '                               <span class="input-label-unit">元/月</span>\n' +
                        '                           </div>\n' +*/
                        '                       </div>\n' +
                        '                  </div>\n';
                    var dwStr = "元/月";
                    if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                        dwStr = "元/㎡·天";
                    } else {
                        str += sffsStr;
                    }
                    str += '           <div class="layui-form-item">\n' +
                        '                       <div class="layui-inline">\n' +
                        '                           <label class="layui-form-label">默认价格：</label>\n' +
                        '                           <div class="layui-input-inline" style="width: 320px;">\n';
                    if (val == "669791dac4894160bc8d79b484519e96" || val == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                        str += '<input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="-1" title="固定价格" checked="checked">';
                        str += '                           <div class="layui-input-inline ' + val + '-fixed-price" style="display: none; position: absolute; right: 0;">\n' +
                            '                               <input type="number" name="payFixedJinE" autocomplete="off" class="layui-input">\n' +
                            // '                               <span class="input-label-unit input-label-unit-flag">元/年</span>\n' +
                            '                           </div>' +
                            '                           <div class="layui-input-inline ' + val + '-fixed-price" style="display: none; position: absolute; right: -100px; width: 100px;">' +
                            '                               <select name="ln-sfdw" lay-filter="ln-sfdw">\n' +
                            '                                   <option value="0" selected="">元/年</option>\n' +
                            '                                   <option value="1">元/㎡</option>\n' +
                            '                               </select>' +
                            '                           </div>\n' +
                            '<br>\n';
                    }
                    str += '<input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="0" title="自定义" checked="checked">';
                    str += '                           <div class="layui-input-inline ' + val + '-diy-price" style="position: absolute; right: 0;">\n' +
                        '                               <input type="number" name="payJinE" autocomplete="off" class="layui-input">\n' +
                        '                               <span class="input-label-unit input-label-unit-flag">' + dwStr + '</span>\n' +
                        '                           </div>\n';
                    if (!!priceList) {
                        for (var i = 0; i < priceList.length; i++) {
                            str += '<br><input type="radio" name="' + val + '-unit-price" lay-filter="' + val + '-unit-price" value="' + priceList[i].ID + '" data-price="' + priceList[i].PRICE_TYPE + '" title="' + priceList[i].PRICE_NAME + '">（' + priceList[i].PRICE_TYPE + '<span class="input-label-unit-flag">' + dwStr + '</span>' + '）';
                        }
                    }

                    str += '                           </div>\n' +
                        '                       </div>\n' +
                        '                  </div>\n';
                    str += '                <div class="layui-form-item">\n' +
                        '                       <div class="layui-inline">\n' +
                        '                           <label class="layui-form-label">备注信息：</label>\n' +
                        '                           <div class="layui-input-inline" style="width: 310px;">\n' +
                        '                               <textarea name="property-info" lay-verify="" autocomplete="off" class="layui-textarea"></textarea>\n' +
                        '                           </div>\n' +
                        '                       </div>\n' +
                        '                   </div>' +
                        '              </div>\n' +
                        '          </fieldset>\n' +
                        '      </div>';

                    $(".quote-property-info").find(".layui-input-extra-content").append(str);

                    form.on('radio(' + val + '-unit-price)', function (data) {
                        if (data.value == "-1") {
                            $("." + val + "-diy-price").hide();
                            $("." + val + "-fixed-price").css("display", "inline");
                        } else if (data.value == "0") {
                            $("." + val + "-fixed-price").hide();
                            $("." + val + "-diy-price").css("display", "inline");
                        } else {
                            $("." + val + "-fixed-price").hide();
                            $("." + val + "-diy-price").hide();
                        }
                    });

                    form.render();
                    break;
            }
        } else if (data.elem.checked == false) {
            switch (val) {
                case "a14e6f2e190e4492badac72e9b42152e":
                    $(".water-content").hide();
                    break;
                case "ddcf9b35bbe04cd88834e21c1fd74f32":
                    $(".power-content").hide();
                    break;
                default:
                    $(".layui-input-extra-content").find("." + val + "-content").remove();
                    break;
            }
        }
    });

    // 物业收费日期下拉框
    form.on('select(sfrq)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("天");
        } else if (data.value == "1") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("日");
        }
    });

    // 物业收费金额下拉框
    form.on('select(sfje)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().parent().parent().find(".input-label-unit-flag").html("元/月");
        } else if (data.value == "2") {
            $(this).parent().parent().parent().parent().parent().parent().find(".input-label-unit-flag").html("元/㎡·天");
        }
    });

    // 物业水费收费方式下拉框
    form.on('select(w-sffs)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/月");
            $(".w-sffs-content").css("display", "none");
            $(".w-choose-price").css("display", "none");
            $(".sb-setting-class").hide();
            $(".w-sfrq-content-cb").hide();
            $(".w-sfrq-content-gd").show();
            $(".w-default-price").hide();
            $(".w-sfrq-content-js-other").hide();
            $(".w-sfrq-content-js").hide();
            $(".w-sfrq-content-js-sfrq").show();
            $(".w-diy-price").show();
        } else if (data.value == "1") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/吨");
            $(".w-sffs-content").css("display", "inline-block");
            $(".w-choose-price").css("display", "block");
            $(".w-sffs-content").empty();
            $(".w-default-price").empty();
            $(".w-sfrq-content-js-other").show();
            $(".w-sfrq-content-js").hide();
            change.wSffsChange();
        } else if (data.value == "3") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/吨");
            $(".w-sffs-content").css("display", "inline-block");
            $(".w-choose-price").css("display", "block");
            $(".w-sffs-content").empty();
            $(".w-default-price").empty();
            change.wSffsChange();
            $(".w-sfrq-content-js-other").hide();
            $(".w-sfrq-content-js").show();
        }
    });

    // 物业电费收费方式下拉框
    form.on('select(e-sffs)', function (data) {
        if (data.value == "0") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/月");
            $(".e-sffs-content").css("display", "none");
            $(".e-choose-price").css("display", "none");
            $(".db-setting-class").hide();
            $(".e-sfrq-content-cb").hide();
            $(".e-sfrq-content-gd").show();
            $(".e-default-price").hide();
            $(".e-sfrq-content-js-other").hide();
            $(".e-sfrq-content-js").hide();
            $(".e-sfrq-content-js-sfrq").show();
            $(".e-diy-price").show();
        } else if (data.value == "1") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/度");
            $(".e-sffs-content").css("display", "inline-block");
            $(".e-choose-price").css("display", "block");
            $(".e-sffs-content").empty();
            $(".e-default-price").empty();
            change.eSffsChange();
            $(".e-sfrq-content-js-other").show();
            $(".e-sfrq-content-js").hide();
        } else if (data.value == "3") {
            $(this).parent().parent().parent().parent().find(".input-label-unit").html("元/度");
            $(".e-sffs-content").css("display", "inline-block");
            $(".e-choose-price").css("display", "block");
            $(".e-sffs-content").empty();
            $(".e-default-price").empty();
            change.eSffsChange();
            $(".e-sfrq-content-js-other").hide();
            $(".e-sfrq-content-js").show();
        }
    });

    // 物业水费计价类型单选框点击事件
    form.on('radio(w-pay-type)', function (data) {
        if (data.value == "0") {
            $(".w-pay-type-content").fadeOut(300);
        } else if (data.value == "1") {
            $(".w-pay-type-content").fadeIn(300);
        }
    });

    // 物业电费计价类型单选框点击事件
    form.on('radio(e-pay-type)', function (data) {
        if (data.value == "0") {
            $(".e-pay-type-content").fadeOut(300);
        } else if (data.value == "1") {
            $(".e-pay-type-content").fadeIn(300);
        }
    });

    // 物业水费默认价格单选框点击事件
    form.on('radio(w-unit-price)', function (data) {
        if (data.value == "0") {
            $(".w-default-price").fadeOut(300);
            $(".w-diy-price").fadeIn(300);
        } else {
            $(".w-diy-price").fadeOut(300);
            $(".w-default-price").fadeIn(300);
        }
    });

    // 物业电费默认价格单选框点击事件
    form.on('radio(e-unit-price)', function (data) {
        if (data.value == "0") {
            $(".e-default-price").fadeOut(300);
            $(".e-diy-price").fadeIn(300);
        } else {
            $(".e-diy-price").fadeOut(300);
            $(".e-default-price").fadeIn(300);
        }
    });

    // 物业水费人为比例开关
    form.on('switch(w-rwbl)', function (data) {
        if (this.checked == true) {
            $(".w-rwbl-content").fadeIn(300);
        } else {
            $(".w-rwbl-content").fadeOut(300);
        }
    });

    // 物业电费人为比例开关
    form.on('switch(e-rwbl)', function (data) {
        if (this.checked == true) {
            $(".e-rwbl-content").fadeIn(300);
        } else {
            $(".e-rwbl-content").fadeOut(300);
        }
    });


    /* 以下为代收信息初始化 */
    // 银行下拉框
    form.on('select(bankCode)', function (data) {
        change.bankCodeChange(Number(data.value));
    });
    // 省市联动下拉框
    init.initProviceCity();
    // 省份下拉框
    form.on('select(province)', function (data) {
        change.provinceChange(data.value);
    });
    // 代收开启关闭开关
    form.on('switch(collection)', function (data) {
        collection = data.elem.checked;
    });
    /* 以上为代收信息初始化 */


    // $(".contract-cycle").html(today + " ~ " + today);   // 合同周期初始化赋值
    init.initUser();
    init.initIndustry();
    init.initProperty();
    init.initBusiness();
    init.initContractDate(today, today, today);
    init.initInputChange();

    // 如果是从房间点进来，初始化房间下拉框
    if (!!roomId) {
        operate.initRoomList(roomId);
    }

    edit.initContract(addType);
    // 如果是变更则隐藏暂存和提交按钮并显示变更按钮
    if (addType == "change") {
        contractChange.hideTemporaryStorageBtn();
        // 注释掉此方法则可以实现物业变更
        // contractChange.initDisabled();
    }
});
/**
 * 初始化方法集合
 * 使用： init.function()
 * param: obj传this，调用该方法的对象
 *
 */
var init = {
    // 初始化当前登录用户
    initUser: function () {
        $.ajax({
            url: "/happuser/userInfo",
            data: {},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".user_name").html(res.data.name);
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 根据楼宇ID获取楼宇的水电默认价格
    initHydropower: function (id) {
        var result;
        $.ajax({
            url: "/hydropower/getBuildingHydropowerPrice",
            data: {buildingId: id},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    result = res.data;
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
        return result;
    },
    // 初始化所属行业信息
    initIndustry: function () {
        $.ajax({
            url: "/dictionary/findByCode",
            data: {code: "PRO_007"},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    var data = res.data;
                    if (!!data) {
                        for (var i = 0; i < data.length; i++) {
                            var str = '<option value="' + data[i].ID + '">' + data[i].NAME + '</option>';
                            $("select[name='industry']").append(str);
                        }
                    }
                    form.render("select");
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 初始化物业收费项
    initProperty: function () {
        $.ajax({
            url: "/property/propertyList",
            data: {},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    var data = res.data;
                    if (!!data) {
                        for (var i = 0; i < data.length; i++) {
                            var str = '<div><input type="checkbox" name="extra" lay-filter="extra" value="' + data[i].ID + '" title="' + data[i].CODE + '"></div>';
                            $(".layui-input-checkbox").append(str);
                        }
                    }
                    form.render();
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
        /*
                $.ajax({
                    url: "/dictionary/findByCode",
                    data: {code: "PRO_002"},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            var data = res.data;
                            if (!!data) {
                                for (var i = 2; i < data.length; i++) {
                                    var str = '<div><input type="checkbox" name="extra" lay-filter="extra" value="' + data[i].ID + '" title="' + data[i].NAME + '"></div>';
                                    $(".layui-input-checkbox").append(str);
                                }
                            }
                            form.render();
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.error(XMLHttpRequest.status);
                        console.error(XMLHttpRequest.readyState);
                        console.error(textStatus);
                    }
                });
        */
    },
    // 初始化房间下拉框商圈
    initBusiness: function () {
        $.ajax({
            url: "/business/list",
            data: {},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".business-box-container").empty();
                    if (res.data.length > 0) {
                        for (var i = 0; i < res.data.length; i++) {
                            if (res.data[i].IS_OPEN === "on") {
                                var str = '<dd data-id="' + res.data[i].ID + '" title="' + res.data[i].BUSINESS_NAME + '">' + res.data[i].BUSINESS_NAME + '</dd>';
                                $(".business-box-container").append(str);
                            }
                        }
                    }
                    $(".business-box-container dd").click(function (e) {
                        $(this).addClass('layui-this').siblings().removeClass("layui-this");
                        init.initBuilding($(this).data("id"));
                        $(".building-box-container").show();
                        $(".unit-box-container").hide();
                        $(".floor-box-container").hide();
                        $(".room-box-container").hide();
                    });
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 初始化房间下拉框楼宇
    initBuilding: function (businessId) {
        $.ajax({
            url: "/building/list",
            data: {BUSINESS_ID: businessId},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".building-box-container").empty();
                    if (res.data.length > 0) {
                        for (var i = 0; i < res.data.length; i++) {
                            if (res.data[i].IS_OPEN === "on") {
                                var str = '<dd data-id="' + res.data[i].BUILDING_ID + '" title="' + res.data[i].BUILDING_NAME + '">' + res.data[i].BUILDING_NAME + '</dd>';
                                $(".building-box-container").append(str);
                            }
                        }
                    }
                    $(".building-box-container dd").click(function (e) {
                        $(this).addClass('layui-this').siblings().removeClass("layui-this");
                        init.initUnit($(this).data("id"));
                        $(".unit-box-container").show();
                        $(".floor-box-container").hide();
                        $(".room-box-container").hide();
                    });
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 初始化房间下拉框单元
    initUnit: function (buildingId) {
        $.ajax({
            url: "/building/info",
            data: {BUILDING_ID: buildingId},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".unit-box-container").empty();
                    if (res.unitList.length > 0) {
                        for (var i = 0; i < res.unitList.length; i++) {
                            if (res.unitList[i].IS_OPEN === "on") {
                                var str = '<dd class="dd-unit" data-id="' + res.unitList[i].UNIT_ID + '" title="' + res.unitList[i].UNIT_NAME + ' 单元">' + res.unitList[i].UNIT_NAME + ' 单元</dd>';
                                $(".unit-box-container").append(str);
                            }
                        }
                    }
                    if (res.itemList.length > 0) {
                        for (var i = 0; i < res.itemList.length; i++) {
                            var chooseFlag = "";
                            $.each(chooseIdArray, function (index, value) {
                                if (res.itemList[i].ROOM_ID == value) {
                                    chooseFlag = "checked";
                                }
                            });
                            var cq = "";
                            if (res.itemList[i].PROPERTY_RIGHT_TYPE == "0") {
                                cq = "自有";
                            } else if (res.itemList[i].PROPERTY_RIGHT_TYPE == "1") {
                                cq = "非自有";
                            }
                            var str = '<dd class="dd-item" data-area="' + res.itemList[i].ROOM_AREA + '" data-id="' + res.itemList[i].ROOM_ID + '" title="【' + res.itemList[i].ROOM_TYPE_NAME + '】' + res.itemList[i].ROOM_NUM + '(' + cq + ')' + '">' +
                                '<input type="checkbox" name="cb-item" value="' + res.itemList[i].ROOM_ID + '" data-cq="' + res.itemList[i].PROPERTY_RIGHT_TYPE + '" data-name="' + res.itemList[i].ROOM_NUM + '" data-area="' + res.itemList[i].ROOM_AREA + '" data-wcode="' + res.itemList[i].WATER_CODE + '" data-ecode="' + res.itemList[i].ELECTRIC_CODE + '" ' + chooseFlag + ' lay-filter="cb-item" lay-skin="primary">' +
                                '【' + res.itemList[i].ROOM_TYPE_NAME + '】' + res.itemList[i].ROOM_NUM + '(' + cq + ')' + '</dd>';
                            $(".unit-box-container").append(str);
                        }
                    }
                    form.render();
                    $(".unit-box-container dd.dd-unit").click(function (e) {
                        $(this).addClass('layui-this').siblings().removeClass("layui-this");
                        $(".floor-box-container").show();
                        $(".room-box-container").hide();
                        init.initFloor($(this).data("id"));
                    });
                    $(".unit-box-container dd.dd-item").click(function (e) {
                        $(this).siblings().removeClass("layui-this");
                        $(".floor-box-container").hide();
                        $(".room-box-container").hide();
                        /*var str = "";
                        var bid = "";
                        $(this).parent().parent().find(".business-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += $(this).html();
                            }
                        });
                        $(this).parent().parent().find(".building-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += " / " + $(this).html();
                                bid = $(this).data("id");
                            }
                        });
                        str += " / " + $(this).html();
                        $(this).parent().parent().parent().parent().find("input[name='room']").val(str);
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-id", $(this).data("id"));
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-bid", bid);
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-name", $(this).html());
                        $(this).parent().parent().parent().parent().parent().find(".room-area").show();
                        $(this).parent().parent().parent().parent().parent().find(".room-area").find(".room-area-single").html($(this).data("area"));
                        $(".room-select-box-container").hide();
                        change.rentMoneyChange();*/
                    });
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 初始化房间下拉框楼层
    initFloor: function (unitId) {
        $.ajax({
            url: "/building/floorInfo",
            data: {UNIT_ID: unitId},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".floor-box-container").empty();
                    if (res.data.length > 0) {
                        for (var i = res.data.length - 1; i >= 0; i--) {
                            var chooseFlag = "";
                            $.each(chooseIdArray, function (index, value) {
                                if (res.data[i].FLOOR_ID == value) {
                                    chooseFlag = "checked";
                                }
                            });
                            if (res.data[i].IS_OPEN === "on") {
                                var str = '<dd data-id="' + res.data[i].FLOOR_ID + '" data-bid="' + res.data[i].BUILDING_ID + '" title="' + res.data[i].FLOOR_NAME + ' 层"><input type="checkbox" name="cb-floor" value="' + res.data[i].FLOOR_ID + '" lay-filter="cb-floor" lay-skin="primary" ' + chooseFlag + '> ' + res.data[i].FLOOR_NAME + ' 层</dd>';
                                $(".floor-box-container").append(str);
                            }
                        }
                    }
                    form.render();
                    $(".floor-box-container dd").click(function (e) {
                        $(this).addClass('layui-this').siblings().removeClass("layui-this");
                        init.initRoom($(this).data("bid"), $(this).data("id"));
                        $(".room-box-container").show();
                        e.stopPropagation();
                    });
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 初始化房间下拉框房间
    initRoom: function (buildingId, floorId) {
        $.ajax({
            url: "/room/list",
            data: {BUILDING_ID: buildingId, FLOOR_ID: floorId},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    $(".room-box-container").empty();
                    var chooseFlag = "";
                    $.each(chooseIdArray, function (index, value) {
                        if (floorId == value) {
                            chooseFlag = "checked";
                        }
                    });
                    if (chooseFlag == "checked") {
                        for (var i = 0; i < res.data.length; i++) {
                            chooseIdArray = $.grep(chooseIdArray, function (value) {
                                return value != res.data[i].ROOM_ID;
                            });
                            for (var j = 0; j < chooseItemArray.length; j++) {
                                if (chooseItemArray[j].id == res.data[i].ROOM_ID) {
                                    chooseItemArray.splice(j, 1);
                                    j--;
                                }
                            }
                        }
                        for (var i = 0; i < res.data.length; i++) {
                            chooseIdArray.push(res.data[i].ROOM_ID);
                            var obj = {};
                            obj.id = res.data[i].ROOM_ID;
                            obj.name = res.data[i].ROOM_NUM;
                            obj.area = res.data[i].ROOM_AREA;
                            obj.type = res.data[i].PROPERTY_RIGHT_TYPE;
                            if (!!res.data[i].WATER_CODE && res.data[i].WATER_CODE != undefined && res.data[i].WATER_CODE != "undefined") {
                                obj.wid = res.data[i].WATER_CODE;
                            } else {
                                obj.wid = "";
                            }
                            if (!!res.data[i].ELECTRIC_CODE && res.data[i].ELECTRIC_CODE != undefined && res.data[i].ELECTRIC_CODE != "undefined") {
                                obj.eid = res.data[i].ELECTRIC_CODE;
                            } else {
                                obj.eid = "";
                            }
                            chooseItemArray.push(obj);
                        }
                    }
                    if (res.data.length > 0) {
                        for (var i = 0; i < res.data.length; i++) {
                            var chooseFlag1 = "";
                            $.each(chooseIdArray, function (index, value) {
                                if (res.data[i].ROOM_ID == value) {
                                    chooseFlag1 = "checked";
                                }
                            });
                            if (res.data[i].IS_OPEN === "on") {
                                var cq = "";
                                if (res.data[i].PROPERTY_RIGHT_TYPE == "0") {
                                    cq = "自有";
                                } else if (res.data[i].PROPERTY_RIGHT_TYPE == "1") {
                                    cq = "非自有";
                                }
                                var str = '<dd data-id="' + res.data[i].ROOM_ID + '" data-wcode="' + res.data[i].WATER_CODE + '" data-ecode="' + res.data[i].ELECTRIC_CODE + '" data-area="' + res.data[i].ROOM_AREA + '" title="' + res.data[i].ROOM_NUM + '(' + cq + ')' + '">' +
                                    '<input type="checkbox" name="cb-room" value="' + res.data[i].ROOM_ID + '" data-cq="' + res.data[i].PROPERTY_RIGHT_TYPE + '" data-name="' + res.data[i].ROOM_NUM + '" data-area="' + res.data[i].ROOM_AREA + '" data-wcode="' + res.data[i].WATER_CODE + '" data-ecode="' + res.data[i].ELECTRIC_CODE + '" lay-filter="cb-room" lay-skin="primary" ' + chooseFlag1 + '>' +
                                    ' ' + res.data[i].ROOM_NUM + '(' + cq + ')' + '</dd>';
                                $(".room-box-container").append(str);
                            }
                        }
                    }
                    form.render();
                    change.itemSelectChange();
                    // 已经选择的不可以再次选择
                    $("textarea[name='room']").each(function () {
                        var id = $(this).attr('data-id');
                        if (!!id) {
                            $(".room-box-container").find("dd").each(function () {
                                if ($(this).attr('data-id') == id) {
                                    $(this).remove();
                                }
                            });
                        }
                    });
                    $(".room-box-container dd").click(function (e) {
                        // $(this).addClass('layui-this').siblings().removeClass("layui-this");
                        /*var str = "";
                        var bid = "";
                        $(this).parent().parent().find(".business-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += $(this).html();
                            }
                        });
                        $(this).parent().parent().find(".building-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += " / " + $(this).html();
                                bid = $(this).data("id");
                            }
                        });
                        $(this).parent().parent().find(".unit-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += " / " + $(this).html();
                            }
                        });
                        $(this).parent().parent().find(".floor-box-container dd").each(function () {
                            if ($(this).hasClass("layui-this")) {
                                str += " / " + $(this).html();
                            }
                        });
                        str += " / " + $(this).html();
                        $(this).parent().parent().parent().parent().find("input[name='room']").val(str);
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-id", $(this).data("id"));
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-bid", bid);
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-wid", $(this).data("wcode"));
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-eid", $(this).data("ecode"));
                        $(this).parent().parent().parent().parent().find("input[name='room']").attr("data-name", $(this).html());
                        $(this).parent().parent().parent().parent().parent().find(".room-area").show();
                        $(this).parent().parent().parent().parent().parent().find(".room-area").find(".room-area-single").html($(this).data("area"));
                        $(".room-select-box-container").hide();
                        change.rentMoneyChange();*/
                    });
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
    },
    // 所有的折扣的输入框绑定输入事件
    initInputChange: function () {
        $(".contract-discount-body").find("input").unbind("input");
        $(".contract-discount-body").find("input").on("input", function () {
            change.change($(this));
        });
    },
    // 初始化合同签订日期、计租日期、结束日期
    initContractDate: function (aDate, bDate, cDate) {
        // 初始化合同签订日期
        laydate.render({
            elem: '#contract-signing-date',
            btns: ['now'],   // 只显示今天按钮
            done: function (value, date, endDate) {
                operate.changeDate('signing', value);
            }
        });
        // 给合同签订日期设置初始值为今天
        $("#contract-signing-date").val(aDate);    // 日期工具类格式化日期
        // 初始化合同计租日期
        laydate.render({
            elem: '#contract-rent-date',
            btns: ['now'],   // 只显示今天按钮
            done: function (value, date, endDate) {
                operate.changeDate('start', value);
            }
        });
        // 给合同计租日期设置初始值为今天
        $("#contract-rent-date").val(bDate);    // 日期工具类格式化日期
        // 初始化合同结束日期
        laydate.render({
            elem: '#contract-finish-date',
            btns: ['now'],   // 只显示今天按钮
            done: function (value, date, endDate) {
                operate.changeDate('finish', value);
            }
        });
        // 给合同结束日期设置初始值为今天
        $("#contract-finish-date").val(cDate);    // 日期工具类格式化日期
    },
    // 初始化省市下拉框
    initProviceCity: function () {
        for (var i = 0; i < region.length; i++) {
            var str = '<option value="' + region[i].name + '">' + region[i].name + '</option>';
            $(".daishou-box").find("select[name='PROVINCE']").append(str);
        }
        form.render("select");
    }
};
/**
 * 操作方法集合
 * 使用： operate.function()
 * param: obj传this，调用该方法的对象
 *
 */
var operate = {

    // 克隆方法
    clone: function (obj) {
        var a = $(obj).parent().parent().find(".clone-box:last");
        var index = $(a).attr("data-index");
        var b = a.clone(true);
        $(b).attr("data-index", parseInt(index) + 1);
        $(b).find(".fa-plus-circle").hide();
        $(b).find(".fa-times-circle").show();

        $(b).find("textarea[name='room']").val("");
        $(b).find("textarea[name='room']").attr("data-id", "");
        $(b).find(".box-container dd").removeClass("layui-this");
        $(b).find(".building-box-container").empty();
        $(b).find(".building-box-container").hide();
        $(b).find(".unit-box-container").empty();
        $(b).find(".unit-box-container").hide();
        $(b).find(".floor-box-container").empty();
        $(b).find(".floor-box-container").hide();
        $(b).find(".room-box-container").empty();
        $(b).find(".room-box-container").hide();

        $(b).find(".room-area-single").empty();
        $(b).find(".room-area").hide();

        $(obj).parent().parent().append(b);
        form.render("select");
        $("input[name='securityDepositMoney']").val(calculate.securityDeposit().toFixed(2));
    },
    // 克隆物业水电表阶梯方法
    cloneExtra: function (obj) {
        var a = $(obj).parent().parent().parent().find(".clone-box:last");
        var index = $(a).attr("data-index");
        var b = a.clone(true);
        $(b).attr("data-index", parseInt(index) + 1);
        $(b).find(".fa-plus-circle").hide();
        $(b).find(".fa-times-circle").show();

        $(b).find("input").val("");

        $(obj).parent().parent().parent().append(b);
    },
    // 克隆押金类型方法
    cloneBondType: function (obj) {
        var str = '<div class="layui-inline">\n' +
            '          <div class="layui-input-inline layui-input-short">\n' +
            '              <input type="text" name="securityDepositName" placeholder="押金名称" lay-verify=""\n' +
            '                     autocomplete="off" class="layui-input">\n' +
            '          </div>\n' +
            '          <div class="layui-input-inline layui-input-longer">\n' +
            '              <input type="number" name="securityDepositPrice" lay-verify=""\n' +
            '                     autocomplete="off" class="layui-input">\n' +
            '              <span class="input-label-unit">元</span>\n' +
            '          </div>\n' +
            '          <i class="fa fa-times-circle" onclick="operate.remove(this, 1);" aria-hidden="true"></i>\n' +
            '      </div>';
        $(".bond-list").append(str);
    },
    // 增加联系人
    addContactPerson: function (obj) {
        var str = '<div class="contact-person-box">\n' +
            '          <div class="layui-inline">\n' +
            '              <label class="layui-form-label">联系人</label>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="text" name="lxr-name" lay-verify="required" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '              <div class="layui-form-mid-red">*</div>\n' +
            '          </div>\n' +
            '          <div class="layui-inline">\n' +
            '              <label class="layui-form-label">联系电话</label>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="tel" name="lxr-tel" lay-verify="required" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '              <div class="layui-form-mid-red">*</div>\n' +
            '              <i class="fa fa-times-circle" aria-hidden="true" onclick="operate.remove(this, 2);"></i>\n' +
            '          </div>\n' +
            '      </div>';
        $(obj).parent().parent().find(".contact-person-arr").append(str);
    },
    // 移除当前信息的方法，tier为几层父级
    remove: function (obj, tier) {
        switch (tier) {
            case 1:
                $(obj).parent().remove();
                break;
            case 2:
                $(obj).parent().parent().remove();
                break;
            case 3:
                $(obj).parent().parent().remove();
                break;
        }
    },
    // 增加免租期，type为前或后，0前、1后
    addUnableRent: function (obj, type) {
        // 判断合同周期有没有值，没有的话不能添加免租期
        var contractCircle = $(".contract-cycle").html();
        if (!contractCircle) {
            return false;
        }
        var date = today;
        if (type === 0) {
            date = $("#contract-rent-date").val();
            var eDate = DateUtils.addDay(-1, new Date(date));

            var str = '<div class="unable-rent-date">\n' +
                '          <input type="text" class="layui-input" id="before-unable-date-start" placeholder="yyyy-MM-dd">\n' +
                '          <span>　~　</span><span id="before-unable-date-end"></span>\n' +
                '          <i onclick="operate.deleteUnableRent(this, 0)" class="fa fa-times" aria-hidden="true"></i>\n' +
                '      </div>';

            $(obj).parent().empty();
            $(".before-unable-rent-date").append(str);

            $("#before-unable-date-end").html(eDate);
            laydate.render({
                elem: '#before-unable-date-start',
                showBottom: false,
                max: eDate
            });
            // 给合同前免租期开始时间设置初始值
            $("#before-unable-date-start").val(eDate);    // 日期工具类格式化日期
        } else if (type === 1) {
            date = $("#contract-finish-date").val();
            var sDate = DateUtils.addDay(1, new Date(date));

            var str = '<div class="unable-rent-date">\n' +
                '          <span id="after-unable-date-start"></span><span>　~　</span>\n' +
                '          <input type="text" class="layui-input" id="after-unable-date-end" placeholder="yyyy-MM-dd">\n' +
                '          <i onclick="operate.deleteUnableRent(this, 1)" class="fa fa-times" aria-hidden="true"></i>\n' +
                '      </div>';

            $(obj).parent().empty();
            $(".after-unable-rent-date").append(str);

            $("#after-unable-date-start").html(sDate);
            laydate.render({
                elem: '#after-unable-date-end',
                showBottom: false,
                min: sDate
            });
            // 给合同后免租期结束时间设置初始值
            $("#after-unable-date-end").val(sDate);    // 日期工具类格式化日期
        }
    },
    // 删除免租期
    deleteUnableRent: function (obj, type) {
        var str = "";
        $(obj).parent().parent().empty();
        if (type === 0) {
            str = '<a onclick="operate.addUnableRent(this, 0)" class="create-rent-detail-btn layui-btn layui-btn-primary layui-btn-small">\n' +
                '      <span>添加合同前免租期</span>\n' +
                '  </a>\n';
            $(".before-unable-rent-date").append(str);
        } else if (type === 1) {
            str = '<a onclick="operate.addUnableRent(this, 1)" class="create-rent-detail-btn layui-btn layui-btn-primary layui-btn-small">\n' +
                '      <span>添加合同后免租期</span>\n' +
                '  </a>';
            $(".after-unable-rent-date").append(str);
        }
    },
    // 通过点击几年的按钮显示不同的递增率和折扣 type为几年，1/3/5
    showDiscount: function (type) {
        $("#contract-finish-date").val(DateUtils.getNextNYearDate($("#contract-rent-date").val(), type));
        operate.appendDiscountSet(type);
        change.change();
    },
    // 通过改变日期显示不同的递增率和折扣 type为改变的哪个时间，date为时间
    changeDate: function (type, date) {
        var sDate = $("#contract-rent-date").val();
        var eDate = $("#contract-finish-date").val();
        if (type === 'start') {
            sDate = date;
        } else if (type === 'finish') {
            eDate = date;
        }
        var years = DateUtils.getYearsDiff(sDate, eDate);
        operate.appendDiscountSet(years);
        change.change();
    },
    // 通过年数生成该显示多少年的设置(实际)
    appendDiscountSet: function (years) {
        // 判断合同外免租期是否开启，开启的话跟随时间变化
        if ($(".before-unable-rent-date").find("i").length > 0) {
            $(".before-unable-rent-date").find("i").click();
            $(".before-unable-rent-date").find("a").click();
        }
        if ($(".after-unable-rent-date").find("i").length > 0) {
            $(".after-unable-rent-date").find("i").click();
            $(".after-unable-rent-date").find("a").click();
        }

        // 设置合同租期
        $(".contract-cycle").html($("#contract-rent-date").val() + " ~ " + $("#contract-finish-date").val());

        // 已经存在的第几年的递增率及折扣
        var hasBody = $(".contract-setting-discount").find(".contract-discount-body").length + 1;

        // 当前租金
        var unitPrice = $("input[name='rentSinglePrice']").val();
        if (!unitPrice) {
            unitPrice = 0;
        }

        // 如果增加的年大于已经存在的则新增；反之则移除。
        if (years > hasBody) {
            for (var i = hasBody + 1; i < years + 1; i++) {
                var str = '<div class="layui-col-md4 contract-discount-body">\n' +
                    '          <div class="layui-form-item">\n' +
                    '              <div class="layui-inline" data-type="unit-div">\n' +
                    '                  <label class="layui-form-label">第' + TypeUtils.NumberToChinese(i) + '年租金：</label>\n' +
                    '                  <div class="layui-input-inline">\n' +
                    '                      <input type="number" name="unit-rent-money" value="' + unitPrice + '" autocomplete="off" class="layui-input">\n' +
                    '                      <span class="input-label-unit change-unit">' + unitHtml + '</span>\n' +
                    '                  </div>\n' +
                    '              </div>\n' +
                    '              <div class="layui-inline" data-type="unit-div-znj">\n' +
                    '                  <label class="layui-form-label">第' + TypeUtils.NumberToChinese(i) + '年滞纳金：</label>\n' +
                    '                  <div class="layui-input-inline">\n' +
                    '                      <input type="number" name="unit-znj-money" value="' + '0' + '" autocomplete="off" class="layui-input">\n' +
                    '                      <span class="input-label-unit">' + '元/天' + '</span>\n' +
                    '                  </div>\n' +
                    '              </div>\n' +
                    '              <div class="layui-inline" data-type="unit-div-dzl">\n' +
                    '                  <label class="layui-form-label">第' + TypeUtils.NumberToChinese(i) + '年递增率：</label>\n' +
                    '                  <div class="layui-input-inline layui-input-shorter">\n' +
                    '                      <input type="number" onchange="change.dzlChange(this);" name="unit-increasing" value="0" autocomplete="off" class="layui-input">\n' +
                    '                      <span class="input-label-unit">%</span>\n' +
                    '                  </div>\n' +
                    '                  <label class="layui-form-label layui-form-label-short">折扣：</label>\n' +
                    '                  <div class="layui-input-inline layui-input-shorter">\n' +
                    '                      <input type="number" name="unit-discount" autocomplete="off" class="layui-input">\n' +
                    '                      <span class="input-label-unit">折</span>\n' +
                    '                  </div>\n' +
                    '                  <div class="layui-input-inline label-unit-money">\n' +
                    '                      折后租金<span class="after-discount-money">' + unitPrice + '.00</span><span class="change-unit">' + unitHtml + '</span>\n' +
                    '                  </div>\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '      </div>';
                $(".contract-setting-discount").append(str);
            }
        } else if (years < hasBody) {
            for (var i = hasBody - 1; i >= years - 1; i--) {
                $(".contract-setting-discount").find(".contract-discount-body").eq(i).remove();
            }
        }

        init.initInputChange();
        change.rentOrdiscountOrIncreasingChange();
    },
    // 新增租金明细
    createRentDetail: function () {
        /* 验证是否选择房源 */
        var flag = true;    // each()中return只跳出循环，加标志位跳出方法
        /*$("input[name='room']").each(function () {
            if (!$(this).data("id")) {
                layer.alert('房源不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                flag = false;
                return false;
            }
        });
        if (flag === false) {
            return false;
        }*/
        if (chooseItemArray.length <= 0) {
            layer.alert('房源不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            flag = false;
            return false;
        }
        /* 验证合同信息是否填全 */
        var rentSinglePrice = $("input[name='rentSinglePrice']").val();
        var securityDepositMonths = $("input[name='securityDepositMonths']").val();
        var securityDepositMoney = $("input[name='securityDepositMoney']").val();
        var payMonths = $("input[name='payMonths']").val();
        var prePayDays = $("input[name='prePayDays']").val();
        if (!rentSinglePrice /*|| !securityDepositMonths*/ || !securityDepositMoney || !payMonths || !prePayDays) {
            layer.alert('合同信息未填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }
        /* 验证合同其他押金是否填写完全 */
        var bondTypeFlag = true;
        $(".bond-list").find("input[name='securityDepositName']").each(function () {
            if ($(this).val() == "") {
                bondTypeFlag = false;
            }
        });
        $(".bond-list").find("input[name='securityDepositPrice']").each(function () {
            if ($(this).val() == "") {
                bondTypeFlag = false;
            }
        });
        if (!bondTypeFlag) {
            layer.alert('合同押金信息未填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }

        /* 验证合同时间是否正确 */
        var sDate = $("#contract-rent-date").val();
        var eDate = $("#contract-finish-date").val();
        var compare = DateUtils.compareTime(sDate, eDate);
        if (compare !== -1) {
            layer.alert('合同结束时间必须大于开始时间', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }
        /* 验证折扣是否在0-10之间 */
        $("input[name='unit-discount']").each(function () {
            if ($(this).val() !== "") {
                if ($(this).val() <= 0 || $(this).val() > 10) {
                    layer.alert('折扣必须在0~10之间，且不可等于0', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    flag = false;
                    return false;
                }
            }
        });
        if (flag === false) {
            return false;
        }

        /* 将提示的状态改为true */
        tips = true;

        // 将暂无数据隐藏
        $(".quote-rent-detail-list").find(".no-data-tips").remove();

        $(".edit-rent-detail-btn").show();
        $(".edit-rent-detail-btngroup").hide();

        // 生成租金详情
        // 根据单位来 0 - 4
        change.createRentDetailTable();

        /* 显示修改明细的按钮 */
        $(".edit-rent-detail-btn").fadeIn(300);

        $(".layui-btn-disabled").removeClass("layui-btn-disabled");

    },
    // 修改租金明细
    editRentDetail: function () {
        layer.confirm('点击编辑，表单数据不再和基础数据联动，提交数据以表单为准', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {

            $(".rent-detail-item-mzq").each(function () {
                $(this).remove();
            });

            $(".container-rent-detail-list").find(".rent-detail-item").each(function (index, elem) {
                if ($(this).hasClass("rent-detail-item-yj")) {
                    var name = $(this).find("div").eq(0).find("span").html();
                    var pDate = $(this).find("div").eq(1).find("span").html();
                    var zzje = $(this).find("div").eq(6).find("span.real-zjje").html();
                    var beizhu = $(this).find("div").eq(7).find("span").html();
                    var fkfpType = $(this).find("div").eq(6).find("span.fkfp-span").data("type");
                    var kfp = $(this).find("div").eq(6).find("span.fkfp-kfp").html();
                    var bkfp = $(this).find("div").eq(6).find("span.fkfp-bkfp").html();
                    var kfpJe = $(this).find("div").eq(6).find("span.fkfp-kfp-je").html();

                    var fkfpStr = "";
                    if (fkfpType == 0) {
                        fkfpStr = '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <select name="unit-fkfp" lay-filter="unit-fkfp">\n' +
                            '                <option value="0" selected="">按比例</option>\n' +
                            '                <option value="1">固定金额</option>\n' +
                            '            </select>' +
                            '      </div>\n';
                        fkfpStr += '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <input oninput="change.changeFkfp(this);" type="number" name="unit-fkfp-num" value="' + kfp + '" lay-verify="" autocomplete="off" class="layui-input">\n' +
                            '            <span class="input-label-unit">%</span>\n' +
                            '        </div>';
                        fkfpStr += '<div class="layui-input-inline" style="width: 200px;">\n' +
                            '            <span><span class="unit-kfpJe">' + kfpJe + '</span>开发票</span>\n' +
                            '       </div>';
                    } else if (fkfpType == 1) {
                        kfpJe = kfp;
                        fkfpStr = '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <select name="unit-fkfp" lay-filter="unit-fkfp">\n' +
                            '                <option value="0">按比例</option>\n' +
                            '                <option value="1" selected="">固定金额</option>\n' +
                            '            </select>' +
                            '      </div>\n';
                        fkfpStr += '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <input oninput="change.changeFkfp(this);" type="number" name="unit-fkfp-num" value="' + kfpJe + '" lay-verify="" autocomplete="off" class="layui-input">\n' +
                            '            <span class="input-label-unit">元</span>\n' +
                            '        </div>';
                        fkfpStr += '<div class="layui-input-inline" style="width: 200px;">\n' +
                            '            <span><span class="unit-kfpJe"></span>开发票</span>\n' +
                            '       </div>';
                    }

                    var str = '<li class="rent-detail-item rent-detail-item-yj">\n' +
                        '          <div>\n' +
                        '              \n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <span class="yjname">' + name + '</span>\n' +
                        '              </div>\n' +
                        '              \n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="text" value="' + pDate + '" class="layui-input layui-date payDate">\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  -\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  -\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  -\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  -\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline" style="width: 120px;">\n' +
                        '                  <input type="number" oninput="change.changeFkfp(this);" name="edit-zzje" value="' + zzje + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n' +
                        '              ' + fkfpStr + '\n' +
                        '          </div>\n' +
                        '          <div class="discounts-select">\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="text" name="edit-beizhu" value="' + beizhu + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n';
                        if (addType == "change") {
                            str += '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n';
                        }
                        str += '          </div>\n' +
                        '      </li>';
                    $(".container-rent-detail-list").append(str);
                } else {
                    var year = $(this).data("year");
                    var jcdj = $("input[name='rentSinglePrice']").val();
                    if (year != 1) {
                        jcdj = $(".contract-setting-discount").find(".contract-discount-body").eq(year - 2).find(".after-discount-money").html();
                    }
                    var sDate = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                    var eDate = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                    var pDate = $(this).find("div").eq(1).find("span").html();
                    var znj = 0;
                    if ($(this).find("div").eq(2).find("span").html() != undefined) {
                        znj = $(this).find("div").eq(2).find("span").html();
                    }
                    var dzl = 0;
                    if ($(this).find("div").eq(3).find("span").html() != undefined) {
                        dzl = $(this).find("div").eq(3).find("span").html().replace("%", "");
                    }
                    if (dzl == "" || dzl == " - " || dzl == undefined) {
                        dzl = 0;
                    }
                    var zk = 10;
                    if ($(this).find("div").eq(4).find("span").html() != undefined) {
                        zk = $(this).find("div").eq(4).find("span").html().replace("折", "");
                    }
                    if (zk == "" || zk == " - " || zk == undefined) {
                        zk = 10;
                    }
                    var zjdj = $(this).find("div").eq(5).find("span").html();
                    var zzje = $(this).find("div").eq(6).find("span.real-zjje").html();
                    var beizhu = $(this).find("div").eq(7).find("span").html();

                    var fkfpType = $(this).find("div").eq(6).find("span.fkfp-span").data("type");
                    var kfp = $(this).find("div").eq(6).find("span.fkfp-kfp").html();
                    var bkfp = $(this).find("div").eq(6).find("span.fkfp-bkfp").html();
                    var kfpJe = $(this).find("div").eq(6).find("span.fkfp-kfp-je").html();

                    var fkfpStr = "";
                    if (fkfpType == 0) {
                        fkfpStr = '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <select name="unit-fkfp" lay-filter="unit-fkfp">\n' +
                            '                <option value="0" selected="">按比例</option>\n' +
                            '                <option value="1">固定金额</option>\n' +
                            '            </select>' +
                            '      </div>\n';
                        fkfpStr += '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <input oninput="change.changeFkfp(this);" type="number" name="unit-fkfp-num" value="' + kfp + '" lay-verify="" autocomplete="off" class="layui-input">\n' +
                            '            <span class="input-label-unit">%</span>\n' +
                            '        </div>';
                        fkfpStr += '<div class="layui-input-inline" style="width: 200px;">\n' +
                            '            <span><span class="unit-kfpJe">' + kfpJe + '</span>开发票</span>\n' +
                            '       </div>';
                    } else if (fkfpType == 1) {
                        kfpJe = kfp;
                        fkfpStr = '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <select name="unit-fkfp" lay-filter="unit-fkfp">\n' +
                            '                <option value="0">按比例</option>\n' +
                            '                <option value="1" selected="">固定金额</option>\n' +
                            '            </select>' +
                            '      </div>\n';
                        fkfpStr += '<div class="layui-input-inline" style="width: 100px;">\n' +
                            '            <input oninput="change.changeFkfp(this);" type="number" name="unit-fkfp-num" value="' + kfpJe + '" lay-verify="" autocomplete="off" class="layui-input">\n' +
                            '            <span class="input-label-unit">元</span>\n' +
                            '        </div>';
                        fkfpStr += '<div class="layui-input-inline" style="width: 200px;">\n' +
                            '            <span><span class="unit-kfpJe"></span>开发票</span>\n' +
                            '       </div>';
                    }

                    var str = '<li class="rent-detail-item" data-year="' + year + '" data-jcdj="' + jcdj + '">\n' +
                        '          <div>\n';

                    if (index != $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                        str += '              <i onclick="operate.addRentItem(this);" class="fa fa-plus item-add" aria-hidden="true"></i>\n';
                    }

                    str += '              <div class="layui-input-inline">\n';

                    if (addType != "change" && index == 1) {
                        str += '                  <span class="startDate" data-value="' + sDate + '" style="display: block; width: 105px;">' + sDate + '</span>\n';
                    } else {
                        str += '                  <input type="text" data-value="' + sDate + '" value="' + sDate + '" class="layui-input layui-date startDate">\n' +
                            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n';
                    }

                    str += '              </div>\n' +
                        '              -\n' +
                        '              <div class="layui-input-inline">\n';

                    if (addType != "change" && index == $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                        str += '                  <span class="endDate" data-value="' + eDate + '" style="display: block; width: 105px;">' + eDate + '</span>\n';
                    } else {
                        str += '                  <input type="text" data-value="' + eDate + '" value="' + eDate + '" class="layui-input layui-date endDate">\n' +
                            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n';
                    }

                    str += '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="text" value="' + pDate + '" class="layui-input layui-date payDate">\n' +
                        '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="number" name="edit-znj" value="' + znj + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n';

                    if (year == 1) {
                        str += '                  <span>' + dzl + '%</spa>\n';
                    } else {
                        str += '                  <input type="number" oninput="change.editInputChange(this, 1);" name="edit-dzl" value="' + dzl + '" autocomplete="off" class="layui-input">\n' +
                            '                  <span class="input-label-unit">%</span>\n';
                    }

                    str += '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="number" oninput="change.editInputChange(this, 2);" name="edit-zk" value="' + zk + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="number" oninput="change.editInputChange(this, 3);" name="edit-zjdj" value="' + zjdj + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n' +
                        '          </div>\n' +
                        '          <div>\n' +
                        '              <div class="layui-input-inline" style="width: 120px;">\n' +
                        '                  <input type="number" oninput="change.changeFkfp(this);" name="edit-zzje" value="' + zzje + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n' +
                        '              ' + fkfpStr + '\n' +
                        '          </div>\n' +
                        '          <div class="discounts-select">\n' +
                        '              <div class="layui-input-inline">\n' +
                        '                  <input type="text" name="edit-beizhu" value="' + beizhu + '" autocomplete="off" class="layui-input">\n' +
                        '              </div>\n';
                    /*'          </div>\n';
                    '          <div class="discounts-select">\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <select name="discounts" lay-filter="discounts">\n' +
                    '                      <option value=""> </option>\n' +
                    /!*'                      <option value="0">免租期</option>\n' +
                    '                      <option value="1">其他优惠</option>\n' +*!/
                    '                  </select>\n' +
                    '              </div>\n';*/
                    if (addType != "change" && index > 1 && index < $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                        str += '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n';
                    } else if (addType == "change") {
                        str += '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n';
                    }
                    str += '          </div>\n' +
                        '      </li>';
                    if (index > 0 && $(this).find("div").eq(2).find("span").html() != undefined && $(this).find("div").eq(3).find("span").html() != undefined) {
                        $(".container-rent-detail-list").append(str);
                    }
                }
                // 将编辑的租金详情隐藏
                $(this).remove();
            });
            $(".layui-date").each(function () {
                laydate.render({
                    elem: this,
                    btns: ['now']   // 只显示今天按钮
                });
            });
            form.render("select");
            change.editInputChange();
            layer.close(index);
            $(".edit-rent-detail-btn").hide();
            $(".edit-rent-detail-btngroup").show();
        });
    },
    // 增加租金明细单条
    addRentItem: function (obj) {
        var year = $(obj).parent().parent().data("year");
        var jcdj = $(obj).parent().parent().data("jcdj");
        var date = $(obj).parent().parent().find(".endDate").val();
        var fpzb = $("input[name='unit-fkfp']").val();
        var str = '<li class="rent-detail-item" data-year="' + year + '" data-jcdj="' + jcdj + '">\n' +
            '          <div>\n' +
            '              <i onclick="operate.addRentItem(this);" class="fa fa-plus item-add" aria-hidden="true"></i>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="text" data-value="" value="' + date + '" class="layui-input layui-date startDate">\n' +
            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
            '              </div>\n' +
            '              -\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="text" data-value="" value="' + date + '" class="layui-input layui-date endDate">\n' +
            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
            '              </div>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="text" value="' + date + '" class="layui-input layui-date payDate">\n' +
            '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
            '              </div>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="number" name="edit-znj" value="0" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="number" oninput="change.editInputChange(this, 1);" name="edit-dzl" value="0" autocomplete="off" class="layui-input">\n' +
            '                  <span class="input-label-unit">%</span>\n' +
            '              </div>\n' +
            '          </div>' +
            '          <div>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="number" oninput="change.editInputChange(this, 2);" name="edit-zk" value="10" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="number" oninput="change.editInputChange(this, 3);" name="edit-zjdj" value="0.00" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <div class="layui-input-inline" style="width: 120px;">\n' +
            '                  <input type="number" oninput="change.changeFkfp(this);" name="edit-zzje" value="0.00" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '              <div class="layui-input-inline" style="width: 100px;">\n' +
            '                  <select name="unit-fkfp" lay-filter="unit-fkfp">\n' +
            '                      <option value="0" selected="">按比例</option>\n' +
            '                      <option value="1">固定金额</option>\n' +
            '                  </select>\n' +
            '              </div>\n' +
            '              <div class="layui-input-inline" style="width: 100px;">\n' +
            '                  <input oninput="change.changeFkfp(this);" type="number" name="unit-fkfp-num" value="' + fpzb + '" lay-verify="" autocomplete="off" class="layui-input">\n' +
            '                  <span class="input-label-unit">%</span>\n' +
            '              </div>\n' +
            '              <div class="layui-input-inline" style="width: 200px;">\n' +
            '                  <span><span class="unit-kfpJe">0.00</span>开发票</span>\n' +
            '              </div>' +
            '          </div>\n' +
            '          <div class="discounts-select">\n' +
            '              <div class="layui-input-inline">\n' +
            '                  <input type="text" name="edit-beizhu" value="" autocomplete="off" class="layui-input">\n' +
            '              </div>\n' +
            '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n' +
            '          </div>\n' +
            '      </li>';
        $(obj).parent().parent().after(str);
        $(".layui-date").each(function () {
            laydate.render({
                elem: this,
                btns: ['now']   // 只显示今天按钮
            });
        });
        form.render('select');
    },
    // 取消修改租金明细
    cancelEditRentDetail: function () {
        layer.confirm('是否放弃手动修改所填的数据，重新生成账单？', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {
            // 生成租金详情
            change.createRentDetailTable();
            layer.close(index);
            $(".edit-rent-detail-btngroup").hide();
            $(".edit-rent-detail-btn").show();
        });
    },
    // 保存修改的租金明细
    saveEditRentDetail: function () {
        // 生成租金详情
        layer.confirm('是否保存所修改的数据？', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {
            // 保存生成租金详情
            change.saveRentDetailTable();
            layer.close(index);
            $(".edit-rent-detail-btngroup").hide();
            $(".edit-rent-detail-btn").show();
        });
    },
    // 取消新建合同
    cancel: function () {
        // 当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
        parent.layer.close(index); // 再执行关闭
    },
    // 提交合同前验证
    validate: function () {
        var zlf = $("input[name='TRNANTRY']:checked").val();    // 租赁方

        var htbh = $("input[name='CONTRACT_NUM']").val();    // 合同编号
        if (!htbh) {
            layer.alert('合同编号不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }

        if (zlf == 0) {
            var gsm = $("input[name='COMPANY']").val();    // 公司名
            if (!gsm) {
                layer.alert('公司名不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }
        } else if (zlf == 1) {
            var xm = $("input[name='NAME']").val();    // 姓名
            if (!xm) {
                layer.alert('姓名不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }
            var sfz = $("input[name='ID_CARD']").val();    // 身份证号
            if (!sfz) {
                layer.alert('身份证号不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                return false;
            }
        }

        var sshy = $("select[name='industry']").val();    // 所属行业
        if (!sshy) {
            layer.alert('所属行业不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }

        var qdr = $("input[name='SIGN_REN']").val();    // 签订人
        if (!qdr) {
            layer.alert('签订人不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }

        var lxdh = $("input[name='SIGN_TEL']").val();    // 联系电话
        /*if (!lxdh) {
            layer.alert('联系电话不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
            return false;
        }*/

        var flag = true;    // each()中return只跳出循环，加标志位跳出方法
        $("input[name='lxr-name']").each(function () {
            if (!$(this).val()) {
                layer.alert('联系人姓名不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                flag = false;
                return false;
            }
        });

        if (!flag) {
            return false;
        }

        $("input[name='lxr-tel']").each(function () {
            if (!$(this).val()) {
                layer.alert('联系人电话不能为空', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                flag = false;
                return false;
            }
        });

        if (!flag) {
            return false;
        }

        return true;

    },
    // 提交合同前验证物业账单
    validateProperty: function (propertys) {

        if (propertys.length == 0) {
            return true;
        } else {
            for (var i = 0; i < propertys.length; i++) {
                var p = propertys[i];
                if (p.PROPERTY_TYPE_ID == "a14e6f2e190e4492badac72e9b42152e" || p.PROPERTY_TYPE_ID == "ddcf9b35bbe04cd88834e21c1fd74f32") {
                    if (p.CHARGE_TYPE == "1" || p.CHARGE_TYPE == "3") {
                        return true;
                    } else {
                        if ($(".property-rent-detail-item").length == 0) {
                            layer.alert('请先生成物业账单', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                            return false;
                        } else {
                            return true;
                        }
                    }
                } else {
                    if ($(".property-rent-detail-item").length == 0) {
                        layer.alert('请先生成物业账单', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                        return false;
                    } else {
                        return true;
                    }
                }
            }
        }

        return true;

    },
    // 生成物业账单
    createPropertyRentDetail: function () {
        // 物业合同数组
        var propertys = new Array();
        $(".extra-content").each(function () {
            if ($(this).css("display") !== "none") {
                var property = {};
                var id = $(this).data("id");
                if (id == 'a14e6f2e190e4492badac72e9b42152e') {
                    property.PROPERTY_TYPE_ID = id;
                    property.CODE = $(this).find("legend").html();
                    property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                    property.CHARGE_TYPE = $(this).find("select[name='w-sffs']").val();
                    property.START_MONTH = "";
                    property.START_DAY = "";
                    property.END_MONTH = "";
                    property.END_DAY = "";

                    if (property.CHARGE_TYPE == 0) {
                        property.CHARGE_DATE_TYPE = $(this).find(".w-sfrq-content-js-sfrq").find("select[name='w-sfrq']").val();
                        property.CHARGE_DATE = $(this).find(".w-sfrq-content-js-sfrq").find(".w-sfrq-content-gd").find("input[name='w-payRiQi']").val();
                    } else if (property.CHARGE_TYPE == 1) {
                        property.CHARGE_DATE_TYPE = "2";
                        property.CHARGE_DATE = $(this).find(".w-sfrq-content-js-sfrq").find(".w-sfrq-content-cb").find("input[name='w-payRiQi']").val();
                    } else if (property.CHARGE_TYPE == 3) {
                        property.CHARGE_DATE_TYPE = $(this).find(".w-sfrq-content-js").find("select[name='w-sfrq']").val();
                        property.CHARGE_DATE = $(this).find(".w-sfrq-content-js").find("input[name='w-payRiQi']").val();
                    }

                    property.VALUATION_TYPE = $(this).find("input[name='w-pay-type']:checked").val();
                    var rwbl = $(this).find("input[name='w-rwbl']").is(":checked");
                    if (rwbl) {
                        property.PEOPLE_BI = 1;
                    } else {
                        property.PEOPLE_BI = 0;
                    }
                    if (property.VALUATION_TYPE == 1) {
                        var tirereds = new Array();
                        $(".w-pay-type-content").find(".clone-box").each(function () {
                            var tirered = {};
                            tirered.START_READ = $(this).find("input[name='price_min']").val();
                            tirered.END_READ = $(this).find("input[name='price_max']").val();
                            tirered.PRICE = $(this).find("input[name='price']").val();
                            tirereds.push(tirered);
                        });
                        property.TIRERED = tirereds;
                    } else {
                        property.TIRERED = "";
                    }
                    property.ANTH_PROPORTION = "";
                    var fpzb = $(this).find("input[name='property-fpzb']").val();
                    if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                        fpzb = 0;
                    }
                    property.PROPERTY_FPZB = fpzb;

                    if (property.CHARGE_TYPE == 0) {
                        property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                        property.IS_DEFAULT = "0";
                        property.DEFAULT_ID = "";
                    } else if (property.CHARGE_TYPE == 1) {
                        var wBid = $(":radio[name='w-unit-price']:checked").val();
                        if (wBid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                            if (!property.CHARGE_PRICE) {
                                layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                                return false;
                            }
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "";
                        } else {
                            property.CHARGE_PRICE = 0;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = wBid;
                        }
                    } else if (property.CHARGE_TYPE == 3) {
                    }

                    // 初始读数
                    var hydropowers = new Array();
                    $(this).find(".w-sbds-list").each(function (index, element) {
                        var hydropower = {};
                        hydropower.ROOM_ID = $(this).find(".data-bid").attr("data-rid");
                        hydropower.HYDROPOWER_ID = $(this).find(".data-bid").attr("data-bid");
                        hydropower.INIT_READ = $(this).find("input[name='dqds']").val();
                        hydropower.INIT_READ_TIME = $(this).find("input[name='cbrq']").val();
                        hydropowers.push(hydropower);
                    });
                    property.INIT_READ = hydropowers;
                    console.log(property.CHARGE_PRICE);
                    console.log(property.IS_DEFAULT);
                    console.log(property.DEFAULT_ID);
                } else if (id == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                    property.PROPERTY_TYPE_ID = id;
                    property.CODE = $(this).find("legend").html();
                    property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                    property.CHARGE_TYPE = $(this).find("select[name='e-sffs']").val();
                    property.START_MONTH = "";
                    property.START_DAY = "";
                    property.END_MONTH = "";
                    property.END_DAY = "";

                    if (property.CHARGE_TYPE == 0) {
                        property.CHARGE_DATE_TYPE = $(this).find(".e-sfrq-content-js-sfrq").find("select[name='e-sfrq']").val();
                        property.CHARGE_DATE = $(this).find(".e-sfrq-content-js-sfrq").find(".e-sfrq-content-gd").find("input[name='e-payRiQi']").val();
                    } else if (property.CHARGE_TYPE == 1) {
                        property.CHARGE_DATE_TYPE = "2";
                        property.CHARGE_DATE = $(this).find(".e-sfrq-content-js-sfrq").find(".e-sfrq-content-cb").find("input[name='e-payRiQi']").val();
                    } else if (property.CHARGE_TYPE == 3) {
                        property.CHARGE_DATE_TYPE = $(this).find(".e-sfrq-content-js").find("select[name='e-sfrq']").val();
                        property.CHARGE_DATE = $(this).find(".e-sfrq-content-js").find("input[name='e-payRiQi']").val();
                    }

                    property.VALUATION_TYPE = $(this).find("input[name='e-pay-type']:checked").val();
                    var rwbl = $(this).find("input[name='e-rwbl']").is(":checked");
                    if (rwbl) {
                        property.PEOPLE_BI = 1;
                    } else {
                        property.PEOPLE_BI = 0;
                    }
                    if (property.VALUATION_TYPE == 1) {
                        var tirereds = new Array();
                        $(".e-pay-type-content").find(".clone-box").each(function () {
                            var tirered = {};
                            tirered.START_READ = $(this).find("input[name='price_min']").val();
                            tirered.END_READ = $(this).find("input[name='price_max']").val();
                            tirered.PRICE = $(this).find("input[name='price']").val();
                            tirereds.push(tirered);
                        });
                        property.TIRERED = tirereds;
                    } else {
                        property.TIRERED = "";
                    }
                    property.ANTH_PROPORTION = "";
                    var fpzb = $(this).find("input[name='property-fpzb']").val();
                    if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                        fpzb = 0;
                    }
                    property.PROPERTY_FPZB = fpzb;

                    if (property.CHARGE_TYPE == 0) {
                        property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                        property.IS_DEFAULT = "0";
                        property.DEFAULT_ID = "";
                    } else if (property.CHARGE_TYPE == 1) {
                        var eBid = $(":radio[name='e-unit-price']:checked").val();
                        if (eBid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                            if (!property.CHARGE_PRICE) {
                                layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                                return false;
                            }
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "";
                        } else {
                            property.CHARGE_PRICE = 0;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = eBid;
                        }
                    } else if (property.CHARGE_TYPE == 3) {
                    }

                    // 初始读数
                    var hydropowers = new Array();
                    $(this).find(".e-dbds-list").each(function (index, element) {
                        var hydropower = {};
                        hydropower.ROOM_ID = $(this).find(".data-bid").attr("data-rid");
                        hydropower.HYDROPOWER_ID = $(this).find(".data-bid").attr("data-bid");
                        hydropower.INIT_READ = $(this).find("input[name='dqds']").val();
                        hydropower.INIT_READ_TIME = $(this).find("input[name='cbrq']").val();
                        hydropowers.push(hydropower);
                    });
                    property.INIT_READ = hydropowers;
                } else if (id == "669791dac4894160bc8d79b484519e96" || id == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                    property.PROPERTY_TYPE_ID = id;
                    property.CODE = $(this).find("legend").html();
                    property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                    property.CHARGE_DATE_TYPE = $(this).find("select[name='sfrq']").val();
                    property.CHARGE_DATE = $(this).find("input[name='payRiQi']").val();
                    if (!property.CHARGE_DATE) {
                        layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                        return false;
                    }
                    property.CHARGE_TYPE = $(this).find("select[name='sfje']").val();
                    property.VALUATION_TYPE = 0;
                    property.PEOPLE_BI = 0;
                    property.TIRERED = "";
                    property.ANTH_PROPORTION = "";
                    property.START_MONTH = $(this).find("input[name='jfzqStartMonth']").val();
                    property.START_DAY = $(this).find("input[name='jfzqStartDay']").val();
                    property.END_MONTH = $(this).find("input[name='jfzqEndMonth']").val();
                    property.END_DAY = $(this).find("input[name='jfzqEndDay']").val();
                    var fpzb = $(this).find("input[name='property-fpzb']").val();
                    if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                        fpzb = 0;
                    }
                    property.PROPERTY_FPZB = fpzb;
                    var bid = $(this).find("input[type='radio']:checked").val();
                    var bprice = $(this).find("input[type='radio']:checked").data("price");
                    if (bid == "-1") {
                        property.LN_UNIT = $(this).find("select[name='ln-sfdw']").val();
                        property.CHARGE_PRICE = $(this).find("input[name='payFixedJinE']").val();
                        if (!property.CHARGE_PRICE) {
                            layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                            return false;
                        }
                        property.IS_DEFAULT = "0";
                        property.DEFAULT_ID = "-1";
                    } else if (bid == "0") {
                        property.CHARGE_PRICE = $(this).find("input[name='payJinE']").val();
                        if (!property.CHARGE_PRICE) {
                            layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                            return false;
                        }
                        property.IS_DEFAULT = "0";
                        property.DEFAULT_ID = "0";
                    } else {
                        property.CHARGE_PRICE = bprice;
                        property.IS_DEFAULT = "1";
                        property.DEFAULT_ID = bid;
                    }
                } else {
                    property.PROPERTY_TYPE_ID = id;
                    property.CODE = $(this).find("legend").html();
                    property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                    property.CHARGE_DATE_TYPE = $(this).find("select[name='sfrq']").val();
                    property.CHARGE_DATE = $(this).find("input[name='payRiQi']").val();
                    property.CHARGE_TYPE = $(this).find("select[name='sfje']").val();
                    property.VALUATION_TYPE = 0;
                    property.PEOPLE_BI = 0;
                    property.TIRERED = "";
                    property.ANTH_PROPORTION = "";
                    property.START_MONTH = "";
                    property.START_DAY = "";
                    property.END_MONTH = "";
                    property.END_DAY = "";
                    var fpzb = $(this).find("input[name='property-fpzb']").val();
                    if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                        fpzb = 0;
                    }
                    property.PROPERTY_FPZB = fpzb;
                    var bid = $(this).find("input[type='radio']:checked").val();
                    var bprice = $(this).find("input[type='radio']:checked").data("price");
                    if (bid == "0") {
                        property.CHARGE_PRICE = $(this).find("input[name='payJinE']").val();
                        if (!property.CHARGE_PRICE) {
                            layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                            return false;
                        }
                        property.IS_DEFAULT = "0";
                        property.DEFAULT_ID = "0";
                    } else {
                        property.CHARGE_PRICE = bprice;
                        property.IS_DEFAULT = "1";
                        property.DEFAULT_ID = bid;
                    }
                }
                propertys.push(property);
            }
        });

        // 账单数组
        var bills = new Array();
        // 提醒数组
        var txs = new Array();

        // 物业账单
        for (var i = 0; i < propertys.length; i++) {
            var p = propertys[i];
            if (p.PROPERTY_TYPE_ID != "669791dac4894160bc8d79b484519e96" && p.PROPERTY_TYPE_ID != "7b05982a081e41deb9b46a1f6f5ed5fa") {
                if (p.CHARGE_TYPE != "3" && p.CHARGE_PRICE != 0) {
                    if (!p.PAY_DATE || !p.CHARGE_DATE || !p.CHARGE_PRICE) {
                        layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                        return false;
                    }
                } else {
                    if (!p.PAY_DATE || !p.CHARGE_DATE) {
                        layer.alert('物业合同没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                        return false;
                    }
                }
                var flag = true;
                if (p.CHARGE_TYPE == "1" || p.CHARGE_TYPE == "3") {
                    $(".w-sbds-list .layui-inline").each(function () {
                        if (!$(this).find("input[name='dqds']").val() || !$(this).find("input[name='cbrq']").val()) {
                            flag = false;
                        }
                    });
                    $(".e-dbds-list .layui-inline").each(function () {
                        if (!$(this).find("input[name='dqds']").val() || !$(this).find("input[name='cbrq']").val()) {
                            flag = false;
                        }
                    });
                }
                if (flag == false) {
                    layer.alert('表读数和抄表日期没有填写完全', {title: ' ', btnAlign: 'c', icon: 0, resize: false});
                    return false;
                }
            }

            if (p.CHARGE_TYPE != 1 && p.CHARGE_TYPE != 3) {
                var billss = change.createPropertyDetail(p.PAY_DATE, p.CHARGE_TYPE, p.CHARGE_DATE_TYPE, p.CHARGE_DATE, p.DEFAULT_ID, p.LN_UNIT, p.CHARGE_PRICE, p.CODE, p.PROPERTY_TYPE_ID, p.PROPERTY_FPZB, p.START_MONTH, p.START_DAY, p.END_MONTH, p.END_DAY);
                if (!!billss) {
                    for (var j = 0; j < billss.length; j++) {
                        bills.push(billss[j]);
                    }
                }
            } else if (p.CHARGE_TYPE == 3) {
                var txss = change.createTxDetail(p.PAY_DATE, p.CHARGE_TYPE, p.CHARGE_DATE_TYPE, p.CHARGE_DATE, p.DEFAULT_ID, p.CHARGE_PRICE, p.CODE, p.PROPERTY_TYPE_ID, p.PROPERTY_FPZB, p.START_MONTH, p.START_DAY, p.END_MONTH, p.END_DAY);
                if (!!txss) {
                    for (var j = 0; j < txss.length; j++) {
                        txs.push(txss[j]);
                    }
                }
            }
        }
        $(".property-rent-detail-item").each(function () {
            $(this).remove();
        });
        if (bills.length > 0) {
            // 将暂无数据隐藏
            $(".quote-property-rent-detail-list").find(".no-data-tips").hide();
            $(".edit-property-rent-detail-btn").show();
            $(".edit-property-rent-detail-btngroup").hide();
        } else {
            $(".quote-property-rent-detail-list").find(".no-data-tips").show();
            $(".edit-property-rent-detail-btn").hide();
            $(".edit-property-rent-detail-btngroup").hide();
        }
        for (var i = 0; i < bills.length; i++) {
            var bill = bills[i];
            // 账单
            var fpzb = "无";
            if (bill.ALLOT_BILL == "0") {
                fpzb = "有";
            }
            var str = '<li class="property-rent-detail-item">\n' +
                '          <div>\n' +
                '              <span>' + bill.START_DATE + ' - ' + bill.END_DATE + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + bill.PAY_DATE + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span data-id="' + bill.PROPERTY_ID + '">' + bill.BILL_NAME + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + bill.TOTAL_PRICE + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + fpzb + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-property-rent-detail-list").append(str);
        }

        $(".property-tx-detail-item").each(function () {
            $(this).remove();
        });
        if (txs.length > 0) {
            // 将暂无数据隐藏
            $(".quote-property-tx-detail-list").find(".no-data-tips").hide();
        } else {
            $(".quote-property-tx-detail-list").find(".no-data-tips").show();
        }
        for (var i = 0; i < txs.length; i++) {
            var tx = txs[i];
            // 账单
            var str = '<li class="property-tx-detail-item">\n' +
                '          <div>\n' +
                '              <span>' + tx.START_DATE + ' - ' + tx.END_DATE + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + tx.PAY_DATE + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span data-id="' + tx.PROPERTY_ID + '">' + tx.BILL_NAME + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-property-tx-detail-list").append(str);
        }
    },
    // 修改物业租金明细
    editPropertyRentDetail: function () {
        layer.confirm('点击编辑，表单数据不再和基础数据联动，提交数据以表单为准', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {

            $(".container-property-rent-detail-list").find(".property-rent-detail-item").each(function (index, elem) {
                var sDate = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                var eDate = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                var pDate = $(this).find("div").eq(1).find("span").html();
                var type = $(this).find("div").eq(2).find("span").html();
                var id = $(this).find("div").eq(2).find("span").data("id");
                var zzje = $(this).find("div").eq(3).find("span").html();
                var fpzb = $(this).find("div").eq(4).find("span").html();
                var info = $(this).find("div").eq(5).find("span").html();

                var str = '<li class="property-rent-detail-item">\n' +
                    '          <div>\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" data-value="' + sDate + '" value="' + sDate + '" class="layui-input layui-date startDate">\n' +
                    '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                    '              </div>\n' +
                    '              -\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" data-value="' + eDate + '" value="' + eDate + '" class="layui-input layui-date endDate">\n' +
                    '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" value="' + pDate + '" class="layui-input layui-date payDate">\n' +
                    '                  <span class="input-label-unit-icon"><i class="fa fa-calendar" aria-hidden="true"></i></span>\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" readonly style="cursor: not-allowed;" name="edit-type" data-id="' + id + '" value="' + type + '" autocomplete="off" class="layui-input">\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="number" name="edit-zzje" value="' + zzje + '" autocomplete="off" class="layui-input">\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '          <div class="discounts-select">\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" readonly style="cursor: not-allowed;" name="edit-fpzb" value="' + fpzb + '" autocomplete="off" class="layui-input">\n' +
                    '              </div>\n' +
                    '          </div>\n' +
                    '          <div class="discounts-select">\n' +
                    '              <div class="layui-input-inline">\n' +
                    '                  <input type="text" name="edit-info" value="' + info + '" autocomplete="off" class="layui-input">\n' +
                    '              </div>\n' +
                    '              <i onclick="operate.remove(this, 3);" class="fa fa-times" aria-hidden="true"></i>\n' +
                    '          </div>\n' +
                    '      </li>';
                $(".container-property-rent-detail-list").append(str);
                // 将编辑的租金详情隐藏
                $(this).remove();
            });
            $(".layui-date").each(function () {
                laydate.render({
                    elem: this,
                    btns: ['now']   // 只显示今天按钮
                });
            });

            layer.close(index);
            $(".edit-property-rent-detail-btn").hide();
            $(".edit-property-rent-detail-btngroup").show();
        });
    },
    // 取消修改物业租金明细
    cancelEditPropertyRentDetail: function () {
        layer.confirm('是否放弃手动修改所填的数据，重新生成账单？', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {
            // 生成物业租金详情
            operate.createPropertyRentDetail();
            layer.close(index);
            $(".edit-property-rent-detail-btngroup").hide();
            $(".edit-property-rent-detail-btn").show();
        });
    },
    // 保存修改物业租金明细
    saveEditPropertyRentDetail: function () {
        layer.confirm('是否保存所修改的数据？', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {
            // 保存修改物业租金详情
            change.savePropertyRentDetailTable();
            layer.close(index);
            $(".edit-property-rent-detail-btngroup").hide();
            $(".edit-property-rent-detail-btn").show();
        });
    },
    // 暂存合同
    temporaryStorage: function (obj) {
        operate.submit(obj, 1);
    },
    // 变更合同
    changeContract: function (obj) {
        operate.submit(obj, 2);
    },
    // 提交当期合同
    submit: function (obj, submitType) {
        if (!$(obj).hasClass("layui-btn-disabled")) {

            if (submitType == 0 && roomType == "0") {
                var flag = operate.validate();
                if (!flag) {
                    return false;
                }
            }

            // 房间数组
            var rooms = new Array();
            /*$(".room-box").each(function () {
                var room = {};
                room.ROOM_ID = $(this).find("input[name='room']").attr('data-id');
                room.WATER_ID = $(this).find("input[name='room']").attr('data-wid');
                room.ELEC_ID = $(this).find("input[name='room']").attr('data-eid');
                room.ROOM_AREA = $(this).find(".room-area-single").html();
                rooms.push(room);
            });*/
            $.each(chooseItemArray, function (index, value) {
                var room = {};
                room.ROOM_ID = value.id;
                room.WATER_ID = value.wid;
                room.ELEC_ID = value.eid;
                room.ROOM_AREA = value.area;
                rooms.push(room);
            });

            // 联系人数组
            var contacts = new Array();
            $(".contact-person-box").each(function () {
                var contact = {};
                contact.CONTACTS_NAME = $(this).find("input[name='lxr-name']").val();
                contact.CONTACTS_TEL = $(this).find("input[name='lxr-tel']").val();
                contacts.push(contact);
            });

            var contractNum = $("input[name='CONTRACT_NUM']").val();
            var lease = $("input[name='TRNANTRY']:checked").val();
            var company = $("input[name='COMPANY']").val();
            var name = $("input[name='NAME']").val();
            var byname = $("input[name='byname']").val();
            var industry = $("select[name='industry']").val();
            var buss_code = $("input[name='BUSS_CODE']").val();
            var id_card = $("input[name='ID_CARD']").val();
            var leg_name = $("input[name='LEG_REN']").val();
            var leg_tel = $("input[name='LEG_TEL']").val();
            var address = $("textarea[name='ADDRESS']").val();
            var sign_ren = $("input[name='SIGN_REN']").val();
            var sign_tel = $("input[name='SIGN_TEL']").val();
            var area = $("input[name='totalArea']").val();
            var unit_rent_money = $("input[name='rentSinglePrice']").val();
            var deposit_money = $("input[name='securityDepositMoney']").val();
            var payment_period = $("input[name='payMonths']").val();
            var pay_type = $("select[name='fkrq']").val();
            var ant_pay_day = $("input[name='prePayDays']").val();
            var dzlx = $("input[name='dzlx']:checked").val();
            var info = $("textarea[name='remark']").val();
            var con_date = $("#contract-signing-date").val();
            var con_hr_date = $("#contract-rent-date").val();
            var con_end_date = $("#contract-finish-date").val();
            var con_outf_date = $("#before-unable-date-start").val();
            var con_outl_date = $("#after-unable-date-end").val();
            var state = '2d18b637cacf44cc8cb2ead91e496036';
            if (submitType == 1) {
                state = '93fc91b97d144550aed7ea1c01dd3w03';
            }

            var fkfp = $("input[name='fkfp']:checked").val();
            var unitFkfp = $("input[name='unit-fkfp']").val();
            var late_fee = $("input[name='unit-znj']").val();

            // 押金数组
            var bonds = new Array();
            var fzBond = {};
            fzBond.BOND_NAME = '房租押金';
            fzBond.BOND_MONEY = deposit_money;
            bonds.push(fzBond);

            $(".bond-list").find(".layui-inline").each(function () {
                var bond = {};
                bond.BOND_NAME = $(this).find("input[name='securityDepositName']").val();
                bond.BOND_MONEY = $(this).find("input[name='securityDepositPrice']").val();
                bonds.push(bond);
            });

            // 租户基本信息
            var tenant = {};
            if (lease == 0) {
                tenant.COMPANY_NAME = company;
                tenant.BUSINESS_LICENSE = buss_code;
            } else if (lease == 1) {
                tenant.COMPANY_NAME = name;
                tenant.BUSINESS_LICENSE = id_card;
            }
            tenant.INDUSTRY_ID = industry;
            tenant.LEGAL_PERSON_NAME = leg_name;
            tenant.LEGAL_PERSON_TEL = leg_tel;
            tenant.CONTRACT_ADDRESS = address;
            tenant.BYNAME = byname;

            // 合同基本信息
            var contract = {};
            contract.CONTRACT_NUM = contractNum;
            contract.LEASE = lease;
            contract.SIGNER = sign_ren;
            contract.SIGNER_TEL = sign_tel;
            contract.AREA = area;
            contract.UNIT_RENT_MONEY = unit_rent_money;
            contract.UNIT = unit;
            contract.INFO = info;
            contract.PAY_DAY_MONTH = ftype;
            contract.INCREAS_TYPE = dzlx;
            contract.DEPOSIT_MONEY = deposit_money;
            contract.LATE_FEE = late_fee;
            contract.PAYMENT_PERIOD = payment_period;
            contract.PAY_TYPE = pay_type;
            contract.ANT_PAY_DAY = ant_pay_day;
            contract.CON_DATE = con_date;
            contract.CON_HR_DATE = con_hr_date;
            contract.CON_END_DATE = con_end_date;
            contract.FKFP_TYPE = fkfp;
            contract.FKFP_MONEY = unitFkfp;
            if (!!con_outf_date) {
                contract.CON_OUTF_DATE = con_outf_date;
            } else {
                contract.CON_OUTF_DATE = "";
            }
            if (!!con_outl_date) {
                contract.CON_OUTL_DATE = con_outl_date;
            } else {
                contract.CON_OUTL_DATE = "";
            }
            contract.CHECK_STATE = "01";
            contract.STATE = state;
            contract.BILL_HTML = $(".container-rent-detail-list").html();
            contract.PROPERTY_BILL_HTML = $(".container-property-rent-detail-list").html();
            // 折扣信息
            var discounts = new Array();
            $(".contract-discount-body").each(function (index, element) {
                var discount = {};
                if (index == 0) {
                    discount.FIRST_YEAR = index + 1;
                    discount.RENT_PRICR = unit_rent_money;
                    discount.LATE_FEE = $(this).find("input[name='unit-znj-money']").val();
                    discount.DISCOUNT = $(this).find("input[name='unit-discount']").val();
                    discount.INCREAS_RATE = $(this).find("input[name='unit-increasing']").val();
                    discount.DISCOUNT_RENT = $(this).find(".after-discount-money").html();
                } else {
                    discount.FIRST_YEAR = index + 1;
                    discount.RENT_PRICR = $(this).find("input[name='unit-rent-money']").val();
                    discount.LATE_FEE = $(this).find("input[name='unit-znj-money']").val();
                    discount.DISCOUNT = $(this).find("input[name='unit-discount']").val();
                    discount.INCREAS_RATE = $(this).find("input[name='unit-increasing']").val();
                    discount.DISCOUNT_RENT = $(this).find(".after-discount-money").html();
                }
                discounts.push(discount);
            });

            // 物业合同数组
            var propertys = new Array();
            $(".extra-content").each(function () {
                if ($(this).css("display") !== "none") {
                    var property = {};
                    var id = $(this).data("id");
                    if (id == 'a14e6f2e190e4492badac72e9b42152e') {
                        property.PROPERTY_TYPE_ID = id;
                        property.CODE = $(this).find("legend").html();
                        property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                        property.CHARGE_TYPE = $(this).find("select[name='w-sffs']").val();
                        property.INFO = $(this).find("textarea[name='property-info']").val();
                        property.START_MONTH = "";
                        property.START_DAY = "";
                        property.END_MONTH = "";
                        property.END_DAY = "";
                        property.LN_UNIT = "0";

                        if (property.CHARGE_TYPE == 0) {
                            property.CHARGE_DATE_TYPE = $(this).find(".w-sfrq-content-js-sfrq").find("select[name='w-sfrq']").val();
                            property.CHARGE_DATE = $(this).find(".w-sfrq-content-js-sfrq").find(".w-sfrq-content-gd").find("input[name='w-payRiQi']").val();
                        } else if (property.CHARGE_TYPE == 1) {
                            property.CHARGE_DATE_TYPE = "2";
                            property.CHARGE_DATE = $(this).find(".w-sfrq-content-js-sfrq").find(".w-sfrq-content-cb").find("input[name='w-payRiQi']").val();
                        } else if (property.CHARGE_TYPE == 3) {
                            property.CHARGE_DATE_TYPE = $(this).find(".w-sfrq-content-js").find("select[name='w-sfrq']").val();
                            property.CHARGE_DATE = $(this).find(".w-sfrq-content-js").find("input[name='w-payRiQi']").val();
                        }

                        property.VALUATION_TYPE = $(this).find("input[name='w-pay-type']:checked").val();
                        var rwbl = $(this).find("input[name='w-rwbl']").is(":checked");
                        if (rwbl) {
                            property.PEOPLE_BI = 1;
                        } else {
                            property.PEOPLE_BI = 0;
                        }
                        if (property.VALUATION_TYPE == 1) {
                            var tirereds = new Array();
                            $(".w-pay-type-content").find(".clone-box").each(function () {
                                var tirered = {};
                                tirered.START_READ = $(this).find("input[name='price_min']").val();
                                tirered.END_READ = $(this).find("input[name='price_max']").val();
                                tirered.PRICE = $(this).find("input[name='price']").val();
                                tirereds.push(tirered);
                            });
                            property.TIRERED = tirereds;
                        } else {
                            property.TIRERED = "";
                        }
                        property.ANTH_PROPORTION = "";
                        var fpzb = $(this).find("input[name='property-fpzb']").val();
                        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                            fpzb = 0;
                        }
                        property.PROPERTY_FPZB = fpzb;

                        var wBid = $(":radio[name='w-unit-price']:checked").val();
                        if (wBid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "";
                        } else {
                            property.CHARGE_PRICE = 0;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = wBid;
                        }

                        // 初始读数
                        var hydropowers = new Array();
                        $(this).find(".w-sbds-list .layui-inline").each(function (index, element) {
                            var hydropower = {};
                            hydropower.HYDROPOWER_ID = $(this).data("bid");
                            hydropower.INIT_READ = $(this).find("input[name='dqds']").val();
                            hydropower.INIT_READ_TIME = $(this).find("input[name='cbrq']").val();
                            var bls = new Array();
                            $(this).find("input[name='bl']").each(function () {
                                var bl = {};
                                bl.PROJECTID = $(this).data('project');
                                bl.BL = $(this).val();
                                bls.push(bl);
                            });
                            hydropower.SBBL = bls;
                            hydropowers.push(hydropower);
                        });
                        property.INIT_READ = hydropowers;
                    } else if (id == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                        property.PROPERTY_TYPE_ID = id;
                        property.CODE = $(this).find("legend").html();
                        property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                        property.CHARGE_TYPE = $(this).find("select[name='e-sffs']").val();
                        property.INFO = $(this).find("textarea[name='property-info']").val();
                        property.START_MONTH = "";
                        property.START_DAY = "";
                        property.END_MONTH = "";
                        property.END_DAY = "";
                        property.LN_UNIT = "0";

                        if (property.CHARGE_TYPE == 0) {
                            property.CHARGE_DATE_TYPE = $(this).find(".e-sfrq-content-js-sfrq").find("select[name='e-sfrq']").val();
                            property.CHARGE_DATE = $(this).find(".e-sfrq-content-js-sfrq").find(".e-sfrq-content-gd").find("input[name='e-payRiQi']").val();
                        } else if (property.CHARGE_TYPE == 1) {
                            property.CHARGE_DATE_TYPE = "2";
                            property.CHARGE_DATE = $(this).find(".e-sfrq-content-js-sfrq").find(".e-sfrq-content-cb").find("input[name='e-payRiQi']").val();
                        } else if (property.CHARGE_TYPE == 3) {
                            property.CHARGE_DATE_TYPE = $(this).find(".e-sfrq-content-js").find("select[name='e-sfrq']").val();
                            property.CHARGE_DATE = $(this).find(".e-sfrq-content-js").find("input[name='e-payRiQi']").val();
                        }

                        property.VALUATION_TYPE = $(this).find("input[name='e-pay-type']:checked").val();
                        var rwbl = $(this).find("input[name='e-rwbl']").is(":checked");
                        if (rwbl) {
                            property.PEOPLE_BI = 1;
                        } else {
                            property.PEOPLE_BI = 0;
                        }
                        if (property.VALUATION_TYPE == 1) {
                            var tirereds = new Array();
                            $(".e-pay-type-content").find(".clone-box").each(function () {
                                var tirered = {};
                                tirered.START_READ = $(this).find("input[name='price_min']").val();
                                tirered.END_READ = $(this).find("input[name='price_max']").val();
                                tirered.PRICE = $(this).find("input[name='price']").val();
                                tirereds.push(tirered);
                            });
                            property.TIRERED = tirereds;
                        } else {
                            property.TIRERED = "";
                        }
                        property.ANTH_PROPORTION = "";
                        var fpzb = $(this).find("input[name='property-fpzb']").val();
                        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                            fpzb = 0;
                        }
                        property.PROPERTY_FPZB = fpzb;

                        var eBid = $(":radio[name='e-unit-price']:checked").val();
                        if (eBid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payFangShi']").val();
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "";
                        } else {
                            property.CHARGE_PRICE = 0;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = eBid;
                        }

                        // 初始读数
                        var hydropowers = new Array();
                        $(this).find(".e-dbds-list .layui-inline").each(function (index, element) {
                            var hydropower = {};
                            hydropower.HYDROPOWER_ID = $(this).data("bid");
                            hydropower.INIT_READ = $(this).find("input[name='dqds']").val();
                            hydropower.INIT_READ_TIME = $(this).find("input[name='cbrq']").val();
                            var bls = new Array();
                            $(this).find("input[name='bl']").each(function () {
                                var bl = {};
                                bl.PROJECTID = $(this).data('project');
                                bl.BL = $(this).val();
                                bls.push(bl);
                            });
                            hydropower.DBBL = bls;
                            hydropowers.push(hydropower);
                        });
                        property.INIT_READ = hydropowers;
                    } else if (id == "669791dac4894160bc8d79b484519e96" || id == "7b05982a081e41deb9b46a1f6f5ed5fa") {
                        property.PROPERTY_TYPE_ID = id;
                        property.CODE = $(this).find("legend").html();
                        property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                        property.CHARGE_DATE_TYPE = $(this).find("select[name='sfrq']").val();
                        property.CHARGE_DATE = $(this).find("input[name='payRiQi']").val();
                        property.CHARGE_TYPE = $(this).find("select[name='sfje']").val();
                        property.INFO = $(this).find("textarea[name='property-info']").val();
                        property.VALUATION_TYPE = 0;
                        property.PEOPLE_BI = 0;
                        property.TIRERED = "";
                        property.ANTH_PROPORTION = "";
                        property.START_MONTH = $(this).find("input[name='jfzqStartMonth']").val();
                        property.START_DAY = $(this).find("input[name='jfzqStartDay']").val();
                        property.END_MONTH = $(this).find("input[name='jfzqEndMonth']").val();
                        property.END_DAY = $(this).find("input[name='jfzqEndDay']").val();
                        property.LN_UNIT = "0";
                        var fpzb = $(this).find("input[name='property-fpzb']").val();
                        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                            fpzb = 0;
                        }
                        property.PROPERTY_FPZB = fpzb;
                        var bid = $(this).find("input[type='radio']:checked").val();
                        var bprice = $(this).find("input[type='radio']:checked").data("price");
                        if (bid == "-1") {
                            property.LN_UNIT = $(this).find("select[name='ln-sfdw']").val();
                            property.CHARGE_PRICE = $(this).find("input[name='payFixedJinE']").val();
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "-1";
                        } else if (bid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payJinE']").val();
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "0";
                        } else {
                            property.CHARGE_PRICE = bprice;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = bid;
                        }
                    } else {
                        property.PROPERTY_TYPE_ID = id;
                        property.CODE = $(this).find("legend").html();
                        property.PAY_DATE = $(this).find("input[name='payZhouQi']").val();
                        property.CHARGE_DATE_TYPE = $(this).find("select[name='sfrq']").val();
                        property.CHARGE_DATE = $(this).find("input[name='payRiQi']").val();
                        property.CHARGE_TYPE = $(this).find("select[name='sfje']").val();
                        property.INFO = $(this).find("textarea[name='property-info']").val();
                        property.VALUATION_TYPE = 0;
                        property.PEOPLE_BI = 0;
                        property.TIRERED = "";
                        property.ANTH_PROPORTION = "";
                        property.START_MONTH = "";
                        property.START_DAY = "";
                        property.END_MONTH = "";
                        property.END_DAY = "";
                        property.LN_UNIT = "0";
                        var fpzb = $(this).find("input[name='property-fpzb']").val();
                        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
                            fpzb = 0;
                        }
                        property.PROPERTY_FPZB = fpzb;
                        var bid = $(this).find("input[type='radio']:checked").val();
                        var bprice = $(this).find("input[type='radio']:checked").data("price");
                        if (bid == "0") {
                            property.CHARGE_PRICE = $(this).find("input[name='payJinE']").val();
                            property.IS_DEFAULT = "0";
                            property.DEFAULT_ID = "0";
                        } else {
                            property.CHARGE_PRICE = bprice;
                            property.IS_DEFAULT = "1";
                            property.DEFAULT_ID = bid;
                        }
                    }
                    propertys.push(property);
                }
            });
            /*$(".extra-content:visible").each(function () {

            });*/

            // 账单数组
            var bills = new Array();

            // 房租账单
            $(".rent-detail-item").each(function (index) {
                if (!!$(this).find("div").eq(6).find("span").html()) {
                    var bill = {};
                    var bill1 = {};
                    bill.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                    bill.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                    bill.PAY_DATE = $(this).find("div").eq(1).find("span").html();
                    var znj = $(this).find("div").eq(2).find("span").html();
                    if (znj == " - ") {
                        znj = 0;
                    }
                    bill.LATE_FEE = znj;
                    // bill.TOTAL_PRICE = $(this).find("div").eq(5).find("span.real-zjje").html();
                    bill.INFO = $(this).find("div").eq(7).find("span").html();
                    bill1.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                    bill1.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                    bill1.PAY_DATE = $(this).find("div").eq(1).find("span").html();
                    bill1.LATE_FEE = znj;
                    // bill1.TOTAL_PRICE = $(this).find("div").eq(5).find("span.real-zjje").html();
                    bill1.INFO = $(this).find("div").eq(7).find("span").html();
                    if ($(this).hasClass('rent-detail-item-yj')) {
                        bill.START_DATE = con_hr_date;
                        bill.END_DATE = con_end_date;
                        bill.BILL_TYPE = 1;
                        bill.BILL_NAME = $(this).find("div").eq(0).find("span").html();
                        bill1.START_DATE = con_hr_date;
                        bill1.END_DATE = con_end_date;
                        bill1.BILL_TYPE = 1;
                        bill1.BILL_NAME = $(this).find("div").eq(0).find("span").html();
                    } else {
                        bill.BILL_TYPE = 0;
                        bill.BILL_NAME = "租金";
                        bill1.BILL_TYPE = 0;
                        bill1.BILL_NAME = "租金";
                    }
                    bill.SORT = index;
                    bill.PROPERTY_ID = "";
                    bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill.ACT_PAY_DATE = "";
                    bill.MAKE_BILL_TYPE = 0;
                    bill.ALLOT_BILL = 0;
                    bill1.SORT = index;
                    bill1.PROPERTY_ID = "";
                    bill1.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill1.ACT_PAY_DATE = "";
                    bill1.MAKE_BILL_TYPE = 0;
                    bill1.ALLOT_BILL = 1;
                    /*bill.PAY_TYPE = $(this).find("div").eq(5).find("span.fkfp-span").data("type");
                    if (bill.PAY_TYPE == 0) {
                        bill.PAY_TYPE_PROPORTION = $(this).find("div").eq(5).find("span.fkfp-kfp").html();
                        bill.PAY_TYPE_MONEY = $(this).find("div").eq(5).find("span.fkfp-kfp-je").html();
                    } else if (bill.PAY_TYPE == 1) {
                        bill.PAY_TYPE_PROPORTION = "";
                        bill.PAY_TYPE_MONEY = $(this).find("div").eq(5).find("span.fkfp-kfp").html();
                    }*/

                    var payType = $(this).find("div").eq(6).find("span.fkfp-span").data("type");
                    var fpbl = $(this).find("div").eq(6).find("span.fkfp-kfp").html();

                    var fpje = 0;
                    if (payType == 0) {
                        fpje = $(this).find("div").eq(6).find("span.fkfp-kfp-je").html();
                        bill.TOTAL_PRICE = Number(fpje).toFixed(2);
                        bill1.TOTAL_PRICE = (Number($(this).find("div").eq(6).find("span.real-zjje").html()) - Number(fpje)).toFixed(2);

                        if (fpbl > 0 && fpbl < 100) {
                            bills.push(bill);
                            bills.push(bill1);
                        } else if (fpbl <= 0) {
                            bills.push(bill1);
                        } else if (fpbl >= 100) {
                            bills.push(bill);
                        }
                    } else if (payType == 1) {
                        fpje = $(this).find("div").eq(6).find("span.fkfp-kfp").html();
                        bill.TOTAL_PRICE = Number(fpje).toFixed(2);
                        bill1.TOTAL_PRICE = (Number($(this).find("div").eq(6).find("span.real-zjje").html()) - Number(fpje)).toFixed(2);

                        if (fpje > 0 && fpje < Number($(this).find("div").eq(6).find("span.real-zjje").html())) {
                            bills.push(bill);
                            bills.push(bill1);
                        } else if (fpje <= 0) {
                            bills.push(bill1);
                        } else if (fpje >= Number($(this).find("div").eq(5).find("span.real-zjje").html())) {
                            bills.push(bill);
                        }
                    }
                }
            });

            // 物业账单
            $(".property-rent-detail-item").each(function (index) {
                var bill = {};
                bill.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                bill.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                bill.PAY_DATE = $(this).find("div").eq(1).find("span").html();
                bill.TOTAL_PRICE = $(this).find("div").eq(3).find("span").html();
                bill.BILL_TYPE = 2;
                bill.BILL_NAME = $(this).find("div").eq(2).find("span").html();
                bill.PROPERTY_ID = $(this).find("div").eq(2).find("span").data("id");
                bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                bill.ACT_PAY_DATE = "";
                bill.INFO = $(this).find("div").eq(5).find("span").html();
                bill.SORT = 0;
                bill.MAKE_BILL_TYPE = 0;
                var fp = $(this).find("div").eq(4).find("span").html();
                if (fp == "有") {
                    bill.ALLOT_BILL = 0;
                } else if (fp == "无") {
                    bill.ALLOT_BILL = 1;
                }
                bills.push(bill);
            });

            /*for (var i = 0; i < propertys.length; i++) {
                var p = propertys[i];
                if (p.CHARGE_TYPE != 1) {
                    var billss = change.createPropertyDetail(p.PAY_DATE, p.CHARGE_TYPE, p.CHARGE_DATE_TYPE, p.CHARGE_DATE, p.DEFAULT_ID, p.CHARGE_PRICE, p.CODE, p.PROPERTY_TYPE_ID, p.PROPERTY_FPZB, p.START_MONTH, p.START_DAY, p.END_MONTH, p.END_DAY);
                    if (!!billss) {
                        for (var j = 0; j < billss.length; j++) {
                            bills.push(billss[j]);
                        }
                    }
                }
            }*/
            var flag = operate.validateProperty(propertys);
            if (!flag) {
                return false;
            }

            // 提醒数组
            var reminds = new Array();
            $(".property-tx-detail-item").each(function (index) {
                var tx = {};
                tx.START_DATE = $(this).find("div").eq(0).find("span").html().substring(0, 10);
                tx.END_DATE = $(this).find("div").eq(0).find("span").html().substring(13, 23);
                tx.PAY_DATE = $(this).find("div").eq(1).find("span").html();
                tx.TYPE = $(this).find("div").eq(2).find("span").html();
                reminds.push(tx);
            });

            if (submitType == 2) {
                var BILL_ID = '';
                $("input[name='BILL_ID']").each(function (index) {
                    if ($(this).is(':checked')) {
                        BILL_ID += $(this).val() + ",";
                    }
                });
                BILL_ID = BILL_ID.replace(/(.*)[,，]$/, '$1');
                contract.CONTRACT_ID = contractId;
                contract.BILL_ID = BILL_ID;
            }

            if (collection) {
                var flag = operate.validateCollection();
                if (!flag) {
                    return false;
                }
                contract.IF_COLLECTION = 1;
            } else {
                contract.IF_COLLECTION = 0;
            }

            var collectionData = {};
            collectionData.TX_TEL = $(".daishou-box").find("input[name='TX_TEL']").val();
            collectionData.TX_EMAIL = $(".daishou-box").find("input[name='TX_EMAIL']").val();
            collectionData.BANK_CODE = $(".daishou-box").find("select[name='BANK_CODE']").val();
            collectionData.ACCOUNT_TYPE = $(".daishou-box").find("input[name='ACCOUNT_TYPE']:checked").val();
            collectionData.ACCOUNT_NO = $(".daishou-box").find("input[name='ACCOUNT_NO']").val();
            collectionData.ACCOUNT_NAME = $(".daishou-box").find("input[name='ACCOUNT_NAME']").val();
            collectionData.PROVINCE = $(".daishou-box").find("select[name='PROVINCE']").val();
            collectionData.CITY = $(".daishou-box").find("select[name='CITY']").val();
            collectionData.BANK_NAME = $(".daishou-box").find("input[name='BANK_NAME']").val();
            collectionData.ACCOUNT_PROP = $(".daishou-box").find("input[name='ACCOUNT_PROP']:checked").val();
            collectionData.CURRENCY = $(".daishou-box").find("select[name='CURRENCY']").val();
            collectionData.ID_TYPE = $(".daishou-box").find("select[name='ID_TYPE']").val();
            collectionData.ID = $(".daishou-box").find("input[name='CID']").val();
            collectionData.TEL = $(".daishou-box").find("input[name='TEL']").val();
            collectionData.ABSTRACT = $(".daishou-box").find("textarea[name='ZY']").val();

            var data = {};
            data.ROOMS = rooms;
            data.CONTACTS = contacts;
            data.TENANT = tenant;
            data.CONTRACT = contract;
            data.BONDS = bonds;
            data.DISCOUNT = discounts;
            data.PROPERTY = propertys;
            data.BILL = bills;
            data.REMINDS = reminds;
            data.ATTACHMENT = uploadfiles;
            data.COLLECTION = collectionData;

            // console.log(uploadfiles);
            // console.log(JSON.stringify(contract));
            // console.log(JSON.stringify(bills));
            // console.log(JSON.stringify(rooms));
            // console.log(JSON.stringify(propertys));
            // console.log(JSON.stringify(collectionData));
            var sendData = {};
            sendData.DATA = JSON.stringify(data);

            if (submitType == 0) {
                layer.msg('确认保存合同吗', {
                    time: 0
                    , btn: ['确定', '取消']
                    , shade: 0.3
                    , yes: function (index) {
                        layer.close(index); // 关闭当前提示框
                        var i = parent.layer.getFrameIndex(window.name);
                        // layer.alert(JSON.stringify(data));
                        if (!!contractId) {
                            $.ajax({
                                url: "/contract/delete",
                                data: {id: contractId},
                                dataType: "json",
                                type: "post",
                                async: false,
                                success: function (res) {
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.msg("删除失败");
                                    console.error(XMLHttpRequest.status);
                                    console.error(XMLHttpRequest.readyState);
                                    console.error(textStatus);
                                }
                            });
                        }
                        $.ajax({
                            url: "/contract/save",
                            data: sendData,
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    parent.layer.close(i);  // 关闭新建合同页面
                                    parent.layer.msg("保存成功");   // 父页面弹出保存成功
                                    if (!!$(parent.window.document).find("#htIframe")[0]) {
                                        $(parent.window.document).find("#htIframe")[0].contentWindow.reloadshenheID()
                                    }
                                } else if (res.errcode === "1") {
                                    layer.msg("保存失败");
                                    /*layer.msg(res.errmsg, function () {
                                    });*/
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.msg("保存失败");
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });
                    }
                });
            } else if (submitType == 1) {
                layer.msg('确认暂存合同吗', {
                    time: 0
                    , btn: ['确定', '取消']
                    , shade: 0.3
                    , yes: function (index) {
                        layer.close(index); // 关闭当前提示框
                        var i = parent.layer.getFrameIndex(window.name);
                        // console.log(JSON.stringify(data));
                        if (!!contractId) {
                            $.ajax({
                                url: "/contract/delete",
                                data: {id: contractId},
                                dataType: "json",
                                type: "post",
                                async: false,
                                success: function (res) {
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.msg("删除失败");
                                    console.error(XMLHttpRequest.status);
                                    console.error(XMLHttpRequest.readyState);
                                    console.error(textStatus);
                                }
                            });
                        }
                        $.ajax({
                            url: "/contract/temporaryStorage",
                            data: sendData,
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    parent.layer.close(i);  // 关闭新建合同页面
                                    parent.layer.msg("保存成功");   // 父页面弹出保存成功
                                    if (!!$(parent.window.document).find("#htIframe")[0]) {
                                        $(parent.window.document).find("#htIframe")[0].contentWindow.reloadzancunID()
                                    }
                                } else if (res.errcode === "1") {
                                    layer.msg("保存失败");
                                    /*layer.msg(res.errmsg, function () {
                                    });*/
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.msg("保存失败");
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });
                    }
                });
            } else if (submitType == 2) {
                layer.msg('确认变更合同吗', {
                    time: 0
                    , btn: ['确定', '取消']
                    , shade: 0.3
                    , yes: function (index) {
                        layer.close(index); // 关闭当前提示框
                        var i = parent.layer.getFrameIndex(window.name);
                        // console.log(JSON.stringify(data));
                        if (!!contractId) {
                            $.ajax({
                                url: "/contract/change",
                                data: sendData,
                                dataType: "json",
                                type: "post",
                                async: false,
                                success: function (res) {
                                    parent.layer.close(i);  // 关闭新建合同页面
                                    parent.layer.msg("变更待审核");   // 父页面弹出变更成功
                                    window.parent.frames[0].layui.table.reload("jxzID",{});
                                    window.parent.frames[0].reloadshenheID();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    layer.msg("变更失败");
                                    console.error(XMLHttpRequest.status);
                                    console.error(XMLHttpRequest.readyState);
                                    console.error(textStatus);
                                }
                            });
                        }
                        parent.layer.close(i);  // 关闭新建合同页面
                        parent.layer.msg("变更待审核");   // 父页面弹出变更成功
                    }
                });
            }
        }
        return false;
    }
};
/**
 * 改变方法集合
 * 使用： change.function()
 * param: obj传this，调用该方法的对象
 *
 */
var change = {
    // 房间项目下拉选择框复选框
    itemSelectChange: function () {
        if (chooseItemArray.length > 0) {
            $(".room-select-box-container-btn").show();
        } else {
            $(".room-select-box-container-btn").hide();
        }
    },
    // 总面积改变
    totalAreaChange: function (obj) {
        var totalArea = 0;
        $(".room-area-single").each(function () {
            totalArea += Number($(this).html());
        });
        if ($(obj).val() > totalArea) {
            layer.tips('更改后面积不能大于选择的房间和项目总面积', '.totalAreaInput', {
                tips: [1, '#78BA32'] //还可配置颜色
            });
            $("input[name='totalArea']").val(totalArea.toFixed(2));
        }
    },
    // 有输入值改变
    change: function (obj) {
        // 如果状态为true的话显示小提示
        if (tips === true) {
            $(".quote-rent-detail").find(".quote-title").find(".layui-layer-content").fadeIn(200);
        }
        // 只有当data-type是unit-div里的输入框值改变的时候才去调用重新计算的方法
        if ($(obj).parent().parent().attr("data-type") === "unit-div") {
            change.rentOrdiscountOrIncreasingChange($(obj));
        }
        if ($(obj).attr("name") === "unit-discount") {
            change.rentOrdiscountOrIncreasingChange($(obj));
        }
    },
    // 租金改变
    rentMoneyChange: function () {
        // change.setSecurityDepositMoney();
        // 当前租金
        var unitPrice = $("input[name='rentSinglePrice']").val();
        if (!unitPrice) {
            unitPrice = 0;
        }
        // 每年租金
        $("input[name='unit-rent-money']").val(unitPrice);

        change.rentOrdiscountOrIncreasingChange();
    },
    // 支付方式改变
    payMonthsChange: function (obj) {
        var val = $(obj).val();
        if (ftype != 0) {
            $(".payMonths-btns a").removeClass("layui-this");
            switch (val) {
                case "1":
                    $(".payMonths-btns a").eq(1).addClass("layui-this");
                    break;
                case "3":
                    $(".payMonths-btns a").eq(2).addClass("layui-this");
                    break;
                case "6":
                    $(".payMonths-btns a").eq(3).addClass("layui-this");
                    break;
                case "12":
                    $(".payMonths-btns a").eq(4).addClass("layui-this");
                    break;
            }
            ftype = val;
        }
    },
    // 固定日日期输入验证
    prePayDaysChange: function (obj) {
        if ($("select[name='fkrq']").val() == 1) {
            if ($(obj).val() < 1 || $(obj).val() > 30) {
                $(obj).val("");
                layer.msg("固定日期不能小于1或大于30", function () {
                });
            }
        }
    },
    // 押金月数改变
    setSecurityDepositMoney: function () {
        $("input[name='securityDepositMoney']").val(calculate.securityDeposit().toFixed(2));
    },
    // 租金或折扣或递增率改变，重新生成折后租金
    rentOrdiscountOrIncreasingChange: function (obj) {
        // 当前租金
        var unitPrice = $("input[name='rentSinglePrice']").val();
        // 前一年递增率加当前年递增率
        var preIncreasing = 0;
        // 前一年价格
        var preUnitPrice = 0;
        // 循环计算每一年的价格
        $(".contract-discount-body").each(function (index, element) {
            var unitIncreasing = $(this).find("input[name='unit-increasing']").val();
            var unitDiscount = $(this).find("input[name='unit-discount']").val();
            if (!unitIncreasing) {
                unitIncreasing = 0;
            }
            if (!unitDiscount) {
                unitDiscount = 10;
            }

            /**
             *
             * 原始折后价格计算方法：
             * 当前年的初始单价加上前一年或者原始价格乘递增率后总数乘折扣
             * (jinnian + qiannian或yuanshi * dizenglv) * zhekou
             *
             */
            /*var newUnitPrice = unitPrice;

            if (index === 0) {
                newUnitPrice = unitPrice * (unitDiscount / 10);
            } else {
                var type = $("input[name='dzlx']:checked").val();
                if (type == 0) {
                    preIncreasing += parseFloat(unitIncreasing);
                    var typ = $(this).find("input[name='unit-rent-money']").val();
                    if (!!typ) {
                        newUnitPrice = typ;
                    }
                    newUnitPrice = (parseFloat(newUnitPrice) + parseFloat(newUnitPrice * (preIncreasing / 100))) * (unitDiscount / 10);
                } else if (type == 1) {
                    preIncreasing = parseFloat(unitIncreasing);
                    var typ = $(this).find("input[name='unit-rent-money']").val();
                    if (!!typ) {
                        newUnitPrice = typ;
                    }
                    newUnitPrice = (parseFloat(newUnitPrice) + parseFloat(preUnitPrice * (preIncreasing / 100))) * (unitDiscount / 10);
                }
            }
            preUnitPrice = newUnitPrice;
            $(this).find(".after-discount-money").html(newUnitPrice.toFixed(2));*/

            /**
             *
             * 新折后价格计算方法（折扣率和当前年价格联动）：
             * 当前年的初始单价乘折扣
             * jinnian * zhekou
             *
             */
            var price = $(this).find("input[name='unit-rent-money']").val();
            var type = $("input[name='dzlx']:checked").val();
            var dzl = 0;

            var newUnitPrice = unitPrice;

            if (index == 0) {
                newUnitPrice = parseFloat(unitPrice) * (unitDiscount / 10);
                if (!newUnitPrice) {
                    newUnitPrice = 0;
                }
            }
            else {
                if (type == 0) {
                    newUnitPrice = parseFloat(price) * (unitDiscount / 10);
                    dzl = parseFloat((newUnitPrice - unitPrice) / unitPrice * 100).toFixed(2);
                    $(this).find("input[name='unit-increasing']").val(dzl);
                } else if (type == 1) {
                    newUnitPrice = parseFloat(price) * (unitDiscount / 10);
                    dzl = parseFloat((newUnitPrice - preUnitPrice) / preUnitPrice * 100).toFixed(2);
                    $(this).find("input[name='unit-increasing']").val(dzl);
                }
            }

            preUnitPrice = newUnitPrice;

            $(this).find(".after-discount-money").html(Number(newUnitPrice).toFixed(2));

        });
        change.znjChange();
    },
    // 递增率改变，重新生成折后租金
    dzlChange: function (obj) {
        // 当前租金
        var unitPrice = $("input[name='rentSinglePrice']").val();
        // 前一年递增率加当前年递增率
        var preIncreasing = 0;
        // 前一年价格
        var preUnitPrice = 0;
        // 循环计算每一年的价格
        $(".contract-discount-body").each(function (index, element) {
            var unitIncreasing = $(this).find("input[name='unit-increasing']").val();
            var unitDiscount = $(this).find("input[name='unit-discount']").val();
            if (!unitIncreasing) {
                unitIncreasing = 0;
            }
            if (!unitDiscount) {
                unitDiscount = 10;
            }

            /**
             *
             * 原始折后价格计算方法：
             * 当前年的初始单价加上前一年或者原始价格乘递增率后总数乘折扣
             * (jinnian + qiannian或yuanshi * dizenglv) * zhekou
             *
             */
            /*var newUnitPrice = unitPrice;

            if (index === 0) {
                newUnitPrice = unitPrice * (unitDiscount / 10);
            } else {
                var type = $("input[name='dzlx']:checked").val();
                if (type == 0) {
                    preIncreasing += parseFloat(unitIncreasing);
                    var typ = $(this).find("input[name='unit-rent-money']").val();
                    if (!!typ) {
                        newUnitPrice = typ;
                    }
                    newUnitPrice = (parseFloat(newUnitPrice) + parseFloat(newUnitPrice * (preIncreasing / 100))) * (unitDiscount / 10);
                } else if (type == 1) {
                    preIncreasing = parseFloat(unitIncreasing);
                    var typ = $(this).find("input[name='unit-rent-money']").val();
                    if (!!typ) {
                        newUnitPrice = typ;
                    }
                    newUnitPrice = (parseFloat(newUnitPrice) + parseFloat(preUnitPrice * (preIncreasing / 100))) * (unitDiscount / 10);
                }
            }
            preUnitPrice = newUnitPrice;
            $(this).find(".after-discount-money").html(newUnitPrice.toFixed(2));*/

            /**
             *
             * 新折后价格计算方法（折扣率和当前年价格联动）：
             * 当前年的初始单价乘折扣
             * jinnian * zhekou
             *
             */
            var price = $(this).find("input[name='unit-rent-money']").val();
            var type = $("input[name='dzlx']:checked").val();

            var newUnitPrice = unitPrice;

            if (index == 0) {
                newUnitPrice = parseFloat(unitPrice) * (unitDiscount / 10);
            } else {
                if (type == 0) {
                    newUnitPrice = Number(parseFloat(unitPrice).toFixed(2)) + Number(parseFloat(unitPrice).toFixed(2)) * (unitIncreasing / 100);
                    $(this).find("input[name='unit-rent-money']").val(Number(newUnitPrice).toFixed(2));
                } else if (type == 1) {
                    newUnitPrice = Number(parseFloat(preUnitPrice).toFixed(2)) + Number(parseFloat(preUnitPrice).toFixed(2)) * (unitIncreasing / 100);
                    $(this).find("input[name='unit-rent-money']").val(Number(newUnitPrice).toFixed(2));
                }
            }

            preUnitPrice = newUnitPrice;

            $(this).find(".after-discount-money").html(Number(newUnitPrice).toFixed(2));
        });
        change.znjChange();
    },
    // 滞纳金跟随金额和单位改变
    znjChange: function () {
        $(".contract-discount-body").each(function (index, element) {
            var con_hr_date = $("#contract-rent-date").val();
            var con_end_date = $("#contract-finish-date").val();
            var znjbl = Number($("input[name='unit-znj']").val()) / 100;
            var unitPrice = Number($(this).find(".after-discount-money").html()).toFixed(2);
            var znj = 0;
            switch (unit) {
                case 0:
                    znj = unitPrice * znjbl * Number(calculate.totalArea()).toFixed(2) * 365;
                    break;
                case 1:
                    znj = unitPrice * znjbl * 365;
                    break;
                case 2:
                    znj = unitPrice * znjbl * 12;
                    break;
                case 3:
                    znj = unitPrice * znjbl;
                    break;
                case 4:
                    znj = unitPrice / Number(DateUtils.dateDiff(con_hr_date, con_end_date)) * 365 * znjbl;
                    break;
                case 5:
                    znj = unitPrice * znjbl * Number(calculate.totalArea()).toFixed(2) * 12;
                    break;
            }
            $(this).find("input[name='unit-znj-money']").val(Number(znj).toFixed(2));
        });
    },
    // 生成租金详情
    createRentDetailTable: function () {
        $(".container-rent-detail-list .rent-detail-item-mzq").each(function () {
            $(this).remove();
        });
        $(".container-rent-detail-list .rent-detail-item").each(function () {
            $(this).remove();
        });
        var sDate = $("#contract-rent-date").val();
        var eDate = $("#contract-finish-date").val();
        var allDays = DateUtils.dateDiffInClude(sDate, eDate);
        var years = DateUtils.getYearsDiff(eDate, sDate);
        var startDate = sDate;
        var endDate = eDate;
        var prePayDay = parseInt($("input[name='prePayDays']").val());
        var payMonths = parseInt($("input[name='payMonths']").val());
        var payDateType = $("select[name='fkrq']").val();
        var bs = $("#before-unable-date-start").val();
        var be = $("#before-unable-date-end").html();
        var as = $("#after-unable-date-start").html();
        var ae = $("#after-unable-date-end").val();
        if (!!bs && !!be) {
            var str = '<li class="rent-detail-item-mzq">\n' +
                '          <div>\n' +
                '              <span>' + bs + ' - ' + be + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '合同前免租期' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-rent-detail-list").append(str);
        }

        var fkfp = $("input[name='fkfp']:checked").val();
        var unitFkfp = $("input[name='unit-fkfp']").val();
        if (!unitFkfp) {
            unitFkfp = 0;
        }

        var fkfpStr = '';
        var yjje = Number($("input[name='securityDepositMoney']").val());
        if (fkfp == 0) {
            var kfp = yjje * Number(unitFkfp) / 100;
            var bkfp = yjje - kfp;
            if (bkfp < 0) {
                unitFkfp = 100;
                kfp = yjje;
                bkfp = 0;
            }
            fkfpStr = '<span class="fkfp-span" data-type="0">按比例：<span class="fkfp-kfp">' + unitFkfp + '</span>%(<span class="fkfp-kfp-je">' + Number(kfp).toFixed(2) + '</span>)开发票，<span class="fkfp-bkfp">' + (100 - Number(unitFkfp)) + '</span>%(' + Number(bkfp).toFixed(2) + ')不开发票。</span>';
        } else if (fkfp == 1) {
            var kfp = Number(unitFkfp);
            var bkfp = yjje - Number(unitFkfp);
            if (bkfp < 0) {
                kfp = yjje;
                bkfp = 0;
            }
            fkfpStr = '<span class="fkfp-span" data-type="1">固定金额：<span class="fkfp-kfp">' + Number(kfp).toFixed(2) + '</span>开发票，<span class="fkfp-bkfp">' + Number(bkfp).toFixed(2) + '</span>不开发票。</span>';
        }

        // 押金
        var ystr = '<li class="rent-detail-item rent-detail-item-yj">\n' +
            '          <div>\n' +
            '              <span>房租押金</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            // 合同押金按签订日
            /*'              <span>' + $("#contract-signing-date").val() + '</span>\n' +*/
            // 合同押金按计租日
            '              <span>' + $("#contract-rent-date").val() + '</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span><span class="real-zjje">' + yjje.toFixed(2) + '</span>' + fkfpStr + '</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span>' + '' + '</span>\n' +
            '          </div>\n' +
            '      </li>';
        $(".container-rent-detail-list").append(ystr);

        // 其他押金
        $(".bond-list").find(".layui-inline").each(function () {
            var fkfpStr = '';
            var yjje = Number($(this).find("input[name='securityDepositPrice']").val());
            if (fkfp == 0) {
                var kfp = yjje * Number(unitFkfp) / 100;
                var bkfp = yjje - kfp;
                if (bkfp < 0) {
                    unitFkfp = 100;
                    kfp = yjje;
                    bkfp = 0;
                }
                fkfpStr = '<span class="fkfp-span" data-type="0">按比例：<span class="fkfp-kfp">' + unitFkfp + '</span>%(<span class="fkfp-kfp-je">' + Number(kfp).toFixed(2) + '</span>)开发票，<span class="fkfp-bkfp">' + (100 - Number(unitFkfp)) + '</span>%(' + Number(bkfp).toFixed(2) + ')不开发票。</span>';
            } else if (fkfp == 1) {
                var kfp = Number(unitFkfp);
                var bkfp = yjje - Number(unitFkfp);
                if (bkfp < 0) {
                    kfp = yjje;
                    bkfp = 0;
                }
                fkfpStr = '<span class="fkfp-span" data-type="1">固定金额：<span class="fkfp-kfp">' + Number(kfp).toFixed(2) + '</span>开发票，<span class="fkfp-bkfp">' + Number(bkfp).toFixed(2) + '</span>不开发票。</span>';
            }

            // 押金
            var ystr = '<li class="rent-detail-item rent-detail-item-yj">\n' +
                '          <div>\n' +
                '              <span>' + $(this).find("input[name='securityDepositName']").val() + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                // 合同押金按签订日
                /*'              <span>' + $("#contract-signing-date").val() + '</span>\n' +*/
                // 合同押金按计租日
                '              <span>' + $("#contract-rent-date").val() + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span> - </span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span> - </span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span> - </span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span> - </span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span><span class="real-zjje">' + yjje.toFixed(2) + '</span>' + fkfpStr + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-rent-detail-list").append(ystr);
        });

        if (ftype != 0) {
            // 月
            var months = Math.ceil(DateUtils.getSpacingMonths(sDate, eDate) / parseInt(payMonths));
            if (parseInt(eDate.substring(8, 10)) >= parseInt(sDate.substring(8, 10))) {
                months++;

            }
            for (var i = 0; i < months; i++) {
                var payDate;
                if (payDateType == 0) {
                    // 头一条租金按签订日收费
                    // payDate = $("#contract-signing-date").val();
                    // 头一条租金按计租日收费
                    payDate = $("#contract-rent-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                        payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                    }
                } else if (payDateType == 1) {
                    prePayDay = parseInt($("input[name='prePayDays']").val());
                    if (prePayDay < 10) {
                        prePayDay = "0" + prePayDay;
                    }
                    // 头一条租金按签订日收费
                    // payDate = $("#contract-signing-date").val();
                    // 头一条租金按计租日收费
                    payDate = $("#contract-rent-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                        var y = startDate.substring(0, 4);
                        var m = startDate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                        payDate = startDate.substring(0, 7) + "-" + prePayDay;
                    }
                }

                endDate = DateUtils.dateFormat(new Date(DateUtils.addDay(-1, new Date(DateUtils.addMoth(startDate, parseInt(payMonths))))), "yyyy-MM-dd");
                if (i === months - 1) {
                    endDate = eDate;
                }

                var jcdj = $("input[name='rentSinglePrice']").val();  //基础单价
                var zjdj = $("input[name='rentSinglePrice']").val();  //租金单价
                var zzje = $("input[name='rentSinglePrice']").val();  //最终金额
                var yearCount = DateUtils.getYearsDiff(startDate, sDate);

                var dzl = $("input[name='unit-increasing']").eq(yearCount - 1).val();
                var dzla = 0;
                if (!!dzl && dzl != "0") {
                    dzl = dzl + "%";
                    dzla = parseFloat(dzl);
                } else {
                    dzl = " - ";    //递增率
                }

                var zk = $("input[name='unit-discount']").eq(yearCount - 1).val();
                var zka = $("input[name='unit-discount']").eq(yearCount - 1).val();
                if (!!zk && zk != "0") {
                    zk = zk + "折";
                } else {
                    zk = " - ";    //折扣
                    zka = 10;
                }

                var znj = $("input[name='unit-znj-money']").eq(yearCount - 1).val();
                if (!znj) {
                    znj = 0;
                }

                for (var j = 1; j < yearCount; j++) {
                    var a = $("input[name='unit-increasing']").eq(j - 1).val();
                    if (a == "") {
                        a = 0;
                    }
                    dzla += parseFloat(a);
                }

                jcdj = (parseFloat(jcdj) + parseFloat(jcdj * (dzla / 100))).toFixed(2);
                if (yearCount == 1) {
                    zjdj = (parseFloat(jcdj) * (zka / 10)).toFixed(2);
                }
                if (yearCount > 1) {
                    zjdj = parseFloat($(".after-discount-money").eq(yearCount - 1).html()).toFixed(2);
                }

                var dateDiff = DateUtils.dateDiffInClude(startDate, endDate);

                // 计算账单金额 单位是0
                if (unit == 0) {
                    zzje = Number(zjdj) * dateDiff * parseFloat(calculate.totalArea());
                }
                else if (unit == 1) {
                    zzje = Number(zjdj) * dateDiff;
                }
                else if (unit == 2) {
                    zzje = Number(zjdj) * parseInt(ftype);
                }
                else if (unit == 3) {
                    zzje = Number(zjdj) * parseFloat(parseInt(ftype) / 12);
                }
                else if (unit == 4) {
                    var dayPrice = parseFloat(Number(zjdj) / allDays);
                    zzje = dateDiff * dayPrice;
                }
                else if (unit == 5) {
                    zzje = Number(zjdj) * parseInt(ftype) * parseFloat(calculate.totalArea());
                }

                /*if (i == 0) {
                    zzje += Number($("input[name='securityDepositMoney']").val());
                }*/

                zzje = zzje.toFixed(2);

                var fkfpStr = '';
                var yjje = zzje;
                if (fkfp == 0) {
                    var kfp = yjje * Number(unitFkfp) / 100;
                    var bkfp = yjje - kfp;
                    if (bkfp < 0) {
                        unitFkfp = 100;
                        kfp = yjje;
                        bkfp = 0;
                    }
                    fkfpStr = '<span class="fkfp-span" data-type="0">按比例：<span class="fkfp-kfp">' + unitFkfp + '</span>%(<span class="fkfp-kfp-je">' + Number(kfp).toFixed(2) + '</span>)开发票，<span class="fkfp-bkfp">' + (100 - Number(unitFkfp)) + '</span>%(' + Number(bkfp).toFixed(2) + ')不开发票。</span>';
                } else if (fkfp == 1) {
                    var kfp = Number(unitFkfp);
                    var bkfp = yjje - Number(unitFkfp);
                    if (bkfp < 0) {
                        kfp = yjje;
                        bkfp = 0;
                    }
                    fkfpStr = '<span class="fkfp-span" data-type="1">固定金额：<span class="fkfp-kfp">' + Number(kfp).toFixed(2) + '</span>开发票，<span class="fkfp-bkfp">' + Number(bkfp).toFixed(2) + '</span>不开发票。</span>';
                }

                var str = '<li class="rent-detail-item" data-year="' + yearCount + '">\n' +
                    '          <div>\n' +
                    '              <span>' + startDate + ' - ' + endDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + payDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + znj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + dzl + '</span>\n' +
                    '          </div>\n' +
                    // '          <div>\n' +
                    // '              <span>' + jcdj + '</span>\n' +
                    // '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zk + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zjdj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span><span class="real-zjje">' + zzje + '</span>' + fkfpStr + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + '' + '</span>\n' +
                    '          </div>\n' +
                    '      </li>';
                if (zjdj != "NaN" && zjdj != undefined && zjdj != null && zjdj != "") {
                    $(".container-rent-detail-list").append(str);
                }

            }
        } else {
            // 日
            var days = Math.ceil(DateUtils.dateDiffInClude(sDate, eDate) / parseInt(payMonths));
            for (var i = 0; i < days; i++) {
                endDate = DateUtils.dateFormat(new Date(DateUtils.fromDay(startDate, parseInt(payMonths) - 1)), "yyyy-MM-dd");
                if (i === days - 1) {
                    endDate = eDate;
                }
                var payDate;
                if (payDateType == 0) {
                    // 头一条租金按签订日收费
                    // payDate = $("#contract-signing-date").val();
                    // 头一条租金按计租日收费
                    payDate = $("#contract-rent-date").val();
                    if (i > 0) {
                        payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                    }
                } else if (payDateType == 1) {
                    prePayDay = parseInt($("input[name='prePayDays']").val());
                    if (prePayDay < 10) {
                        prePayDay = "0" + prePayDay;
                    }
                    // 头一条租金按签订日收费
                    // payDate = $("#contract-signing-date").val();
                    // 头一条租金按计租日收费
                    payDate = $("#contract-rent-date").val();
                    if (i > 0) {
                        var y = startDate.substring(0, 4);
                        var m = startDate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                        payDate = startDate.substring(0, 7) + "-" + prePayDay;
                    }
                }


                var jcdj = $("input[name='rentSinglePrice']").val();  //基础单价
                var zjdj = $("input[name='rentSinglePrice']").val();  //租金单价
                var zzje = $("input[name='rentSinglePrice']").val();  //最终金额
                var yearCount = DateUtils.getYearsDiff(startDate, sDate);

                dzl = $("input[name='unit-increasing']").eq(yearCount - 1).val();
                var dzla = 0;
                if (!!dzl && dzl != "0") {
                    dzl = dzl + "%";
                    dzla = parseFloat(dzl);
                } else {
                    dzl = " - ";    //递增率
                }

                zk = $("input[name='unit-discount']").eq(yearCount - 1).val();
                var zka = $("input[name='unit-discount']").eq(yearCount - 1).val();
                if (!!zk && zk != "0") {
                    zk = zk + "折";
                } else {
                    zk = " - ";    //折扣
                    zka = 10;
                }

                var znj = $("input[name='unit-znj-money']").eq(yearCount - 1).val();
                if (!znj) {
                    znj = 0;
                }

                for (var j = 1; j < yearCount; j++) {
                    var a = $("input[name='unit-increasing']").eq(j - 1).val();
                    if (a == "") {
                        a = 0;
                    }
                    dzla += parseFloat(a);
                }

                jcdj = (parseFloat(jcdj) + parseFloat(jcdj * (dzla / 100))).toFixed(2);
                if (yearCount == 1) {
                    zjdj = (parseFloat(jcdj) * (zka / 10)).toFixed(2);
                }
                if (yearCount > 1) {
                    zjdj = parseFloat($(".after-discount-money").eq(yearCount - 1).html()).toFixed(2);
                }

                var dateDiff = DateUtils.dateDiffInClude(startDate, endDate);

                // 计算账单金额 单位是0
                if (unit == 0) {
                    zzje = Number(zjdj) * dateDiff * parseFloat(calculate.totalArea());
                }
                else if (unit == 1) {
                    zzje = Number(zjdj) * dateDiff;
                }
                else if (unit == 2) {
                    zzje = Number(zjdj) * parseFloat(dateDiff / 30);
                }
                else if (unit == 3) {
                    zzje = Number(zjdj) * parseFloat(dateDiff / 12 / 30);
                }
                else if (unit == 4) {
                    var dayPrice = parseFloat(Number(zjdj) / allDays);
                    zzje = dateDiff * dayPrice;
                }
                else if (unit == 5) {
                    zzje = Number(zjdj) * parseFloat(dateDiff / 30) * parseFloat(calculate.totalArea());
                }

                if (i == 0) {
                    zzje += Number($("input[name='securityDepositMoney']").val());
                }

                zzje = zzje.toFixed(2);

                var fkfpStr = '';
                var yjje = zzje;
                if (fkfp == 0) {
                    var kfp = yjje * Number(unitFkfp) / 100;
                    var bkfp = yjje - kfp;
                    if (bkfp < 0) {
                        unitFkfp = 100;
                        kfp = yjje;
                        bkfp = 0;
                    }
                    fkfpStr = '<span class="fkfp-span" data-type="0">按比例：<span class="fkfp-kfp">' + unitFkfp + '</span>%(<span class="fkfp-kfp-je">' + Number(kfp).toFixed(2) + '</span>)开发票，<span class="fkfp-bkfp">' + (100 - Number(unitFkfp)) + '</span>%(' + Number(bkfp).toFixed(2) + ')不开发票。</span>';
                } else if (fkfp == 1) {
                    var kfp = Number(unitFkfp);
                    var bkfp = yjje - Number(unitFkfp);
                    if (bkfp < 0) {
                        kfp = yjje;
                        bkfp = 0;
                    }
                    fkfpStr = '<span class="fkfp-span" data-type="1">固定金额：<span class="fkfp-kfp">' + Number(kfp).toFixed(2) + '</span>开发票，<span class="fkfp-bkfp">' + Number(bkfp).toFixed(2) + '</span>不开发票。</span>';
                }

                var str = '<li class="rent-detail-item" data-year="' + yearCount + '">\n' +
                    '          <div>\n' +
                    '              <span>' + startDate + ' - ' + endDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + payDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + znj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + dzl + '</span>\n' +
                    '          </div>\n' +
                    // '          <div>\n' +
                    // '              <span>' + jcdj + '</span>\n' +
                    // '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zk + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zjdj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span><span class="real-zjje">' + zzje + '</span>' + fkfpStr + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + '' + '</span>\n' +
                    '          </div>\n' +
                    '      </li>';
                if (zjdj != "NaN" && zjdj != undefined && zjdj != null && zjdj != "") {
                    $(".container-rent-detail-list").append(str);
                }

                startDate = DateUtils.dateFormat(new Date(DateUtils.fromDay(endDate, 1)), "yyyy-MM-dd");
            }
        }
        if (!!as && !!ae) {
            var str = '<li class="rent-detail-item-mzq">\n' +
                '          <div>\n' +
                '              <span>' + as + ' - ' + ae + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '合同后免租期' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-rent-detail-list").append(str);
        }
    },
    // 修改生成账单的付款分配
    changeFkfp: function (obj) {
        var fkfpType = $(obj).parent().parent().find("select[name='unit-fkfp']").val();
        var bl = $(obj).parent().parent().find("input[name='unit-fkfp-num']").val();
        if (fkfpType == 0) {
            var zje = $(obj).parent().parent().find("input[name='edit-zzje']").val();
            var kfp = Number(zje) * Number(bl) / 100;
            $(obj).parent().parent().find(".unit-kfpJe").html(kfp.toFixed(2));
        }
    },
    // 生成物业租金详情
    createPropertyDetail: function (fkzq, sffs, sfrqfs, sfrq, unit, lnUnit, sfje, code, id, fpzb, sm, sd, em, ed) {
        var billss = new Array();

        var sDate = $("#contract-rent-date").val();
        var eDate = $("#contract-finish-date").val();
        var payMonths = parseInt(fkzq);
        var startDate = sDate;
        var endDate = eDate;
        var prePayDay = parseInt(sfrq);
        var months = Math.ceil(DateUtils.getSpacingMonths(sDate, eDate) / parseInt(payMonths));
        // var fpzb = $("input[name='property-fpzb']").val();
        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
            fpzb = 0;
        }
        if (id == "669791dac4894160bc8d79b484519e96" || id == "7b05982a081e41deb9b46a1f6f5ed5fa") {
            var hsDate = $("#contract-rent-date").val();
            var heDate = $("#contract-finish-date").val();
            var hsy = hsDate.substring(0, 4);    // 合同开始年份
            var hsm = hsDate.substring(5, 7);    // 合同开始月份
            var hsd = hsDate.substring(8, 10);    // 合同开始日
            var hey = heDate.substring(0, 4);    // 合同结束年份
            var hem = heDate.substring(5, 7);    // 合同结束月份
            var hed = heDate.substring(8, 10);    // 合同结束日
            if (sm < 10) {
                sm = "0" + sm;
            }
            if (sd < 10) {
                sd = "0" + sd;
            }
            if (em < 10) {
                em = "0" + em;
            }
            if (ed < 10) {
                ed = "0" + ed;
            }
            // console.log(hsDate);
            // console.log(heDate);
            // console.log(sm, sd, em, ed);

            var years = DateUtils.getYearsDiff(hsDate, heDate);
            var sfDateE = DateUtils.dateFormat(new Date((Number(hsy) + years) + "-" + sm + "-" + sd), "yyyy-MM-dd");
            if (DateUtils.compareTime(heDate, sfDateE) == 1) {
                years = Number(years) + 1;
            }
            var preSDate = "";
            for (var i = 0; i < years; i++) {
                var sdate = DateUtils.dateFormat(new Date(hsy + "-" + sm + "-" + sd), "yyyy-MM-dd");
                var edate = DateUtils.dateFormat(new Date(hsy + "-" + em + "-" + ed), "yyyy-MM-dd");
                if (i == 0 && DateUtils.compareTime(hsDate, sdate) == 1) {
                    if (DateUtils.compareTime(sdate, edate) == 1) {
                        edate = DateUtils.getAddNYearDate(edate, 1);
                    }
                    if (DateUtils.compareTime(hsDate, edate) == 1) {
                        sdate = DateUtils.getAddNYearDate(sdate, 1);
                        edate = DateUtils.getAddNYearDate(edate, 1);
                    } else {
                        sdate = hsDate;
                    }
                }
                if (DateUtils.compareTime(sdate, edate) == 1) {
                    edate = DateUtils.getAddNYearDate(edate, 1);
                }

                if (DateUtils.compareTime(heDate, sdate) == 1) {
                    if (DateUtils.compareTime(edate, heDate) == 1) {
                        edate = heDate;
                    }
                    // console.log(sdate);
                    // console.log(edate);

                    var bill = {};
                    var bill1 = {};
                    var payDateType = sfrqfs;
                    var payDate;
                    if (payDateType == 0) {
                        /*payDate = $("#contract-signing-date").val();
                        if (i > 0) {
                            startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                            payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                        }*/
                        payDate = DateUtils.addDay(0 - prePayDay, new Date(sdate));
                    } else if (payDateType == 1) {
                        /*prePayDay = parseInt(sfrq);
                        if (prePayDay < 10) {
                            prePayDay = "0" + prePayDay;
                        }
                        payDate = $("#contract-signing-date").val();
                        if (i > 0) {
                            startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                            var y = startDate.substring(0, 4);
                            var m = startDate.substring(5, 7);
                            var d = DateUtils.getDaysOfMonth(y, m);
                            if (prePayDay > d) {
                                prePayDay = d;
                            }
                            payDate = startDate.substring(0, 7) + "-" + prePayDay;
                        }*/
                        if (prePayDay < 10) {
                            prePayDay = "0" + prePayDay;
                        }
                        var y = sdate.substring(0, 4);
                        var m = sdate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                        payDate = sdate.substring(0, 7) + "-" + prePayDay;
                    }

                    /*endDate = DateUtils.dateFormat(new Date(DateUtils.addDay(-1, new Date(DateUtils.addMoth(startDate, parseInt(payMonths))))), "yyyy-MM-dd");
                    if (i === months - 1) {
                        endDate = eDate;
                    }*/

                    bill.START_DATE = sdate;
                    bill.END_DATE = edate;
                    bill1.START_DATE = sdate;
                    bill1.END_DATE = edate;
                    var money = 0;

                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    if (unit == "-1") {
                        if (lnUnit == "1") {
                            money = parseInt(parseFloat(sfje) * parseFloat(calculate.totalArea()));
                        } else {
                            money = sfje;
                        }
                    } else {
                        money = parseInt(DateUtils.dateDiffInClude(sdate, edate)) * parseFloat(sfje) * parseFloat(calculate.totalArea());
                    }

                    bill.TOTAL_PRICE = (money * Number(fpzb) / 100).toFixed(2);
                    bill1.TOTAL_PRICE = (money - bill.TOTAL_PRICE).toFixed(2);

                    bill.BILL_TYPE = 2;
                    bill.BILL_NAME = code;
                    bill.PROPERTY_ID = id;
                    bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill.ACT_PAY_DATE = "";
                    bill.INFO = "";
                    bill.SORT = 0;
                    bill.MAKE_BILL_TYPE = 0;
                    bill.ALLOT_BILL = 0;
                    bill1.BILL_TYPE = 2;
                    bill1.BILL_NAME = code;
                    bill1.PROPERTY_ID = id;
                    bill1.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill1.ACT_PAY_DATE = "";
                    bill1.INFO = "";
                    bill1.SORT = 0;
                    bill1.MAKE_BILL_TYPE = 0;
                    bill1.ALLOT_BILL = 1;
                    if (preSDate != sdate) {
                        if (sffs != 1 && fpzb > 0 && fpzb < 100) {
                            billss.push(bill);
                            billss.push(bill1);
                        } else if (sffs != 1 && fpzb <= 0) {
                            billss.push(bill1);
                        } else if (sffs != 1 && fpzb >= 100) {
                            billss.push(bill);
                        }
                        preSDate = sdate;
                    }

                }
                hsy = Number(hsy) + 1;
                hsDate = hsy + "-" + hsm + "-" + hsd;
            }

            /*if (sm > hsm) {
                var sdate = hsy + "-" + sm + "-" + sd;
                var edate = "";
                if (sm > em) {
                    edate = (Number(hsy) + 1) + "-" + em + "-" + ed;
                } else if (sm < em) {
                    edate = hsy + "-" + em + "-" + ed;
                } else if (sm == em) {
                    if (sd > ed) {
                        edate = (Number(hsy) + 1) + "-" + em + "-" + ed;
                    } else if (sd < ed) {
                        edate = hsy + "-" + em + "-" + ed;
                    } else if (sd == ed) {
                        edate = (Number(hsy) + 1) + "-" + em + "-" + ed;
                    }
                }
            } else if (sm < hsm) {

            }*/
            /*if (sm > em) {
                // 如果开始月份大于结束月份  11    3
                if (sm > hsm) {
                    //    如果开始月份大于合同开始月份

                } else if (sm > hsm) {
                    //    如果开始月份小于合同开始月份

                } else if (sm > hsm) {
                    //    如果开始月份等于合同开始月份

                }
            } else if (sm < em) {
                // 如果开始月份小于结束月份  5    9

            } else if (sm == em) {
                // 如果开始月份等于结束月份  6    6
                if (sd > ed) {
                    // 如果开始日大于结束日

                } else if (sd < ed) {
                    // 如果开始日小于结束日

                } else if (sd == ed) {
                    // 如果开始日等于结束日

                }

            }*/
        } else {
            for (var i = 0; i < months; i++) {
                var bill = {};
                var bill1 = {};
                var payDateType = sfrqfs;
                var payDate;
                if (payDateType == 0) {
                    payDate = $("#contract-signing-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                    }
                    payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                } else if (payDateType == 1) {
                    prePayDay = parseInt(sfrq);
                    if (prePayDay < 10) {
                        prePayDay = "0" + prePayDay;
                    }
                    payDate = $("#contract-signing-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                        var y = startDate.substring(0, 4);
                        var m = startDate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                    }
                    payDate = startDate.substring(0, 7) + "-" + prePayDay;
                }

                endDate = DateUtils.dateFormat(new Date(DateUtils.addDay(-1, new Date(DateUtils.addMoth(startDate, parseInt(payMonths))))), "yyyy-MM-dd");
                if (i === months - 1) {
                    endDate = eDate;
                }

                bill.START_DATE = startDate;
                bill.END_DATE = endDate;
                bill1.START_DATE = startDate;
                bill1.END_DATE = endDate;
                var dateDiff = DateUtils.dateDiffInClude(startDate, endDate);
                var money = 0;
                if (sffs == 1) {
                    bill.PAY_DATE = "";
                    bill.TOTAL_PRICE = "";
                    bill1.PAY_DATE = "";
                    bill1.TOTAL_PRICE = "";
                } else if (sffs == 0) {
                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    money = parseInt(fkzq) * parseFloat(sfje);
                } else if (sffs == 2) {
                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    money = /*parseInt(fkzq) * */parseFloat(sfje) * parseInt(dateDiff) * parseFloat(calculate.totalArea());
                }
                bill.TOTAL_PRICE = (money * Number(fpzb) / 100).toFixed(2);
                bill1.TOTAL_PRICE = (money - bill.TOTAL_PRICE).toFixed(2);

                bill.BILL_TYPE = 2;
                bill.BILL_NAME = code;
                bill.PROPERTY_ID = id;
                bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                bill.ACT_PAY_DATE = "";
                bill.INFO = "";
                bill.SORT = 0;
                bill.MAKE_BILL_TYPE = 0;
                bill.ALLOT_BILL = 0;
                bill1.BILL_TYPE = 2;
                bill1.BILL_NAME = code;
                bill1.PROPERTY_ID = id;
                bill1.STATE = '682177ade393478e8224f9a3aa385a6c';
                bill1.ACT_PAY_DATE = "";
                bill1.INFO = "";
                bill1.SORT = 0;
                bill1.MAKE_BILL_TYPE = 0;
                bill1.ALLOT_BILL = 1;
                if (sffs != 1 && fpzb > 0 && fpzb < 100) {
                    billss.push(bill);
                    billss.push(bill1);
                } else if (sffs != 1 && fpzb <= 0) {
                    billss.push(bill1);
                } else if (sffs != 1 && fpzb >= 100) {
                    billss.push(bill);
                }
            }
        }

        return billss;
    },
    // 生成提醒详情
    createTxDetail: function (fkzq, sffs, sfrqfs, sfrq, unit, sfje, code, id, fpzb, sm, sd, em, ed) {
        var billss = new Array();

        var sDate = $("#contract-rent-date").val();
        var eDate = $("#contract-finish-date").val();
        var payMonths = parseInt(fkzq);
        var startDate = sDate;
        var endDate = eDate;
        var prePayDay = parseInt(sfrq);
        var months = Math.ceil(DateUtils.getSpacingMonths(sDate, eDate) / parseInt(payMonths));
        // var fpzb = $("input[name='property-fpzb']").val();
        if (!fpzb || fpzb == "" || fpzb == undefined || fpzb < 0) {
            fpzb = 0;
        }
        if (id == "669791dac4894160bc8d79b484519e96" || id == "7b05982a081e41deb9b46a1f6f5ed5fa") {
            var hsDate = $("#contract-rent-date").val();
            var heDate = $("#contract-finish-date").val();
            var hsy = hsDate.substring(0, 4);    // 合同开始年份
            var hsm = hsDate.substring(5, 7);    // 合同开始月份
            var hsd = hsDate.substring(8, 10);    // 合同开始日
            var hey = heDate.substring(0, 4);    // 合同结束年份
            var hem = heDate.substring(5, 7);    // 合同结束月份
            var hed = heDate.substring(8, 10);    // 合同结束日
            if (sm < 10) {
                sm = "0" + sm;
            }
            if (sd < 10) {
                sd = "0" + sd;
            }
            if (em < 10) {
                em = "0" + em;
            }
            if (ed < 10) {
                ed = "0" + ed;
            }

            var years = DateUtils.getYearsDiff(hsDate, heDate);
            var sfDateE = DateUtils.dateFormat(new Date((Number(hsy) + years) + "-" + sm + "-" + sd), "yyyy-MM-dd");
            if (DateUtils.compareTime(heDate, sfDateE) == 1) {
                years = Number(years) + 1;
            }
            var preSDate = "";
            for (var i = 0; i < years; i++) {
                var sdate = DateUtils.dateFormat(new Date(hsy + "-" + sm + "-" + sd), "yyyy-MM-dd");
                var edate = DateUtils.dateFormat(new Date(hsy + "-" + em + "-" + ed), "yyyy-MM-dd");
                if (i == 0 && DateUtils.compareTime(hsDate, sdate) == 1) {
                    if (DateUtils.compareTime(sdate, edate) == 1) {
                        edate = DateUtils.getAddNYearDate(edate, 1);
                    }
                    if (DateUtils.compareTime(hsDate, edate) == 1) {
                        sdate = DateUtils.getAddNYearDate(sdate, 1);
                        edate = DateUtils.getAddNYearDate(edate, 1);
                    } else {
                        sdate = hsDate;
                    }
                }
                if (DateUtils.compareTime(sdate, edate) == 1) {
                    edate = DateUtils.getAddNYearDate(edate, 1);
                }

                if (DateUtils.compareTime(heDate, sdate) == 1) {
                    if (DateUtils.compareTime(edate, heDate) == 1) {
                        edate = heDate;
                    }

                    var bill = {};
                    var bill1 = {};
                    var payDateType = sfrqfs;
                    var payDate;
                    if (payDateType == 0) {
                        payDate = DateUtils.addDay(0 - prePayDay, new Date(sdate));
                    } else if (payDateType == 1) {
                        if (prePayDay < 10) {
                            prePayDay = "0" + prePayDay;
                        }
                        var y = sdate.substring(0, 4);
                        var m = sdate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                        payDate = sdate.substring(0, 7) + "-" + prePayDay;
                    }

                    bill.START_DATE = sdate;
                    bill.END_DATE = edate;
                    bill1.START_DATE = sdate;
                    bill1.END_DATE = edate;
                    var money = 0;

                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    if (unit == "-1") {
                        money = sfje;
                    } else {
                        money = parseInt(DateUtils.dateDiffInClude(sdate, edate)) * parseFloat(sfje) * parseFloat(calculate.totalArea());
                    }

                    bill.TOTAL_PRICE = (money * Number(fpzb) / 100).toFixed(2);
                    bill1.TOTAL_PRICE = (money - bill.TOTAL_PRICE).toFixed(2);

                    bill.BILL_TYPE = 2;
                    bill.BILL_NAME = code;
                    bill.PROPERTY_ID = id;
                    bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill.ACT_PAY_DATE = "";
                    bill.INFO = "";
                    bill.SORT = 0;
                    bill.MAKE_BILL_TYPE = 0;
                    bill.ALLOT_BILL = 0;
                    bill1.BILL_TYPE = 2;
                    bill1.BILL_NAME = code;
                    bill1.PROPERTY_ID = id;
                    bill1.STATE = '682177ade393478e8224f9a3aa385a6c';
                    bill1.ACT_PAY_DATE = "";
                    bill1.INFO = "";
                    bill1.SORT = 0;
                    bill1.MAKE_BILL_TYPE = 0;
                    bill1.ALLOT_BILL = 1;
                    if (preSDate != sdate) {
                        if (sffs != 1 && fpzb > 0 && fpzb < 100) {
                            billss.push(bill);
                            billss.push(bill1);
                        } else if (sffs != 1 && fpzb <= 0) {
                            billss.push(bill1);
                        } else if (sffs != 1 && fpzb >= 100) {
                            billss.push(bill);
                        }
                        preSDate = sdate;
                    }

                }
                hsy = Number(hsy) + 1;
                hsDate = hsy + "-" + hsm + "-" + hsd;
            }
        } else {
            for (var i = 0; i < months; i++) {
                var bill = {};
                var bill1 = {};
                var payDateType = sfrqfs;
                var payDate;
                if (payDateType == 0) {
                    payDate = $("#contract-signing-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                    }
                    payDate = DateUtils.addDay(0 - prePayDay, new Date(startDate));
                } else if (payDateType == 1) {
                    prePayDay = parseInt(sfrq);
                    if (prePayDay < 10) {
                        prePayDay = "0" + prePayDay;
                    }
                    payDate = $("#contract-signing-date").val();
                    if (i > 0) {
                        startDate = DateUtils.dateFormat(new Date(DateUtils.addDay(1, new Date(endDate))), "yyyy-MM-dd");
                        var y = startDate.substring(0, 4);
                        var m = startDate.substring(5, 7);
                        var d = DateUtils.getDaysOfMonth(y, m);
                        if (prePayDay > d) {
                            prePayDay = d;
                        }
                    }
                    payDate = startDate.substring(0, 7) + "-" + prePayDay;
                }

                endDate = DateUtils.dateFormat(new Date(DateUtils.addDay(-1, new Date(DateUtils.addMoth(startDate, parseInt(payMonths))))), "yyyy-MM-dd");
                if (i === months - 1) {
                    endDate = eDate;
                }

                bill.START_DATE = startDate;
                bill.END_DATE = endDate;
                bill1.START_DATE = startDate;
                bill1.END_DATE = endDate;
                var money = 0;
                if (sffs == 1) {
                    bill.PAY_DATE = "";
                    bill.TOTAL_PRICE = "";
                    bill1.PAY_DATE = "";
                    bill1.TOTAL_PRICE = "";
                } else if (sffs == 0) {
                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    money = parseInt(fkzq) * parseFloat(sfje);
                } else if (sffs == 2) {
                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    money = parseInt(fkzq) * parseFloat(sfje) * parseFloat(calculate.totalArea());
                } else if (sffs == 3) {
                    bill.PAY_DATE = payDate;
                    bill1.PAY_DATE = payDate;
                    money = 0;
                }
                bill.TOTAL_PRICE = (money * Number(fpzb) / 100).toFixed(2);
                bill1.TOTAL_PRICE = (money - bill.TOTAL_PRICE).toFixed(2);

                bill.BILL_TYPE = 2;
                bill.BILL_NAME = code;
                bill.PROPERTY_ID = id;
                bill.STATE = '682177ade393478e8224f9a3aa385a6c';
                bill.ACT_PAY_DATE = "";
                bill.INFO = "";
                bill.SORT = 0;
                bill.MAKE_BILL_TYPE = 0;
                bill.ALLOT_BILL = 0;
                bill1.BILL_TYPE = 2;
                bill1.BILL_NAME = code;
                bill1.PROPERTY_ID = id;
                bill1.STATE = '682177ade393478e8224f9a3aa385a6c';
                bill1.ACT_PAY_DATE = "";
                bill1.INFO = "";
                bill1.SORT = 0;
                bill1.MAKE_BILL_TYPE = 0;
                bill1.ALLOT_BILL = 1;
                if (sffs != 3 && sffs != 1 && fpzb > 0 && fpzb < 100) {
                    billss.push(bill);
                    billss.push(bill1);
                } else if (sffs != 3 && sffs != 1 && fpzb <= 0) {
                    billss.push(bill1);
                } else if (sffs != 3 && sffs != 1 && fpzb >= 100) {
                    billss.push(bill);
                } else if (sffs == 3) {
                    billss.push(bill);
                }
            }
        }

        return billss;
    },
    // 修改生产的租金详情输入框改变
    editInputChange: function (obj, changeType) {
        var type = $("input[name='dzlx']:checked").val(); // 0原始递增 1前年递增
        var year = $(obj).parent().parent().parent().data("year");  // 当前是第几年
        var ysdj = $("input[name='rentSinglePrice']").val();    // 最原始单价
        var qndj = "";  // 前一年单价

        /*$(".container-rent-detail-list").find(".rent-detail-item").each(function (index, elem) {
            if ($(this).data("year") == year){
                qndj = $(".container-rent-detail-list").find(".rent-detail-item").eq(index - 1).data("jcdj");
                return;
            }
        });*/
        // console.log(year);
        // console.log(ysdj);
        // console.log(qndj);

        var jcdj = $(obj).parent().parent().parent().data("jcdj");  // 基础单价
        var sDate = $(obj).parent().parent().parent().find(".startDate").data("value");   // 开始日期
        var eDate = $(obj).parent().parent().parent().find(".endDate").data("value");   // 结束日期
        var dzl = $(obj).parent().parent().parent().find("input[name='edit-dzl']").val();   // 递增率
        if (!dzl) {
            dzl = 0;
        }
        var zk = $(obj).parent().parent().parent().find("input[name='edit-zk']").val(); // 折扣
        var zjdj = $(obj).parent().parent().parent().find("input[name='edit-zjdj']").val(); // 最终单价
        var zzje = $(obj).parent().parent().parent().find("input[name='edit-zzje']").val(); // 最终金额
        // console.log(jcdj);
        // console.log(dzl);
        // console.log(zk);
        // console.log(zjdj);

        if (changeType != 3) {
            zjdj = (Number(ysdj * (dzl / 100)) + Number(jcdj)) * (zk / 10);
            $(obj).parent().parent().parent().find("input[name='edit-zjdj']").val(zjdj.toFixed(2));
        }

        if (!!jcdj) {
            switch (unit) {
                case 0:
                    zzje = zjdj * calculate.totalArea() * DateUtils.dateDiffInClude(sDate, eDate);
                    break;
                case 1:
                    zzje = zjdj * DateUtils.dateDiffInClude(sDate, eDate);
                    break;
                case 2:
                    zzje = zjdj / 30 * DateUtils.dateDiffInClude(sDate, eDate);
                    break;
                case 3:
                    zzje = zjdj / 365 * DateUtils.dateDiffInClude(sDate, eDate);
                    break;
                case 4:
                    zzje = DateUtils.dateDiffInClude(sDate, eDate) * (ysdj / DateUtils.dateDiffInClude($("#contract-rent-date").val(), $("#contract-finish-date").val()));
                    break;
                case 5:
                    zzje = zjdj / 30 * DateUtils.dateDiffInClude(sDate, eDate);
                    break;
            }
            $(obj).parent().parent().parent().find("input[name='edit-zzje']").val(zzje.toFixed(2));
        }

        change.changeFkfp($(obj).parent());
    },
    // 保存修改后的账单
    saveRentDetailTable: function () {

        var bs = $("#before-unable-date-start").val();
        var be = $("#before-unable-date-end").html();
        var as = $("#after-unable-date-start").html();
        var ae = $("#after-unable-date-end").val();
        if (!!bs && !!be) {
            var str = '<li class="rent-detail-item-mzq">\n' +
                '          <div>\n' +
                '              <span>' + bs + ' - ' + be + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '合同前免租期' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-rent-detail-list").append(str);
        }

        // 押金
        /*var ystr = '<li class="rent-detail-item-mzq">\n' +
            '          <div>\n' +
            '              <span>押金</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span>' + $("#contract-signing-date").val() + '</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span> - </span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span>' + Number($("input[name='securityDepositMoney']").val()).toFixed(2) + '</span>\n' +
            '          </div>\n' +
            '          <div>\n' +
            '              <span>' + '' + '</span>\n' +
            '          </div>\n' +
            '      </li>';
        $(".container-rent-detail-list").append(ystr);*/

        $(".container-rent-detail-list").find(".rent-detail-item").each(function (index, elem) {

            var je = $(this).find("input[name='edit-zzje']").val();
            var fkfpStr = '';
            var fpblNum = $(this).find("input[name='unit-fkfp-num']").val();
            if ($(this).find("select[name='unit-fkfp']").val() == 0) {
                if (Number(fpblNum) > 100) {
                    fpblNum = 100;
                }
                fkfpStr = '<span class="fkfp-span" data-type="0">\n' +
                    '    按比例：\n' +
                    '    <span class="fkfp-kfp">' + fpblNum + '</span>\n' +
                    '    %(\n' +
                    '    <span class="fkfp-kfp-je">' + (Number(je) * Number(fpblNum) / 100).toFixed(2) + '</span>\n' +
                    '    )开发票，\n' +
                    '    <span class="fkfp-bkfp">' + (100 - Number(fpblNum)) + '</span>\n' +
                    '    %(' + (Number(je) - (Number(je) * Number(fpblNum) / 100)).toFixed(2) + ')不开发票。\n' +
                    '</span>';
            } else if ($(this).find("select[name='unit-fkfp']").val() == 1) {
                fkfpStr = '<span class="fkfp-span" data-type="1">\n' +
                    '    固定金额：\n' +
                    '    <span class="fkfp-kfp">' + Number(fpblNum).toFixed(2) + '</span>\n' +
                    '    开发票，\n' +
                    '    <span class="fkfp-bkfp">' + (Number(je) - Number(fpblNum)).toFixed(2) + '</span>\n' +
                    '    不开发票。\n' +
                    '</span>';
            }


            if ($(this).hasClass("rent-detail-item-yj")) {
                var name = $(this).find(".yjname").html();
                var payDate = $(this).find(".payDate").val();
                var zzje = $(this).find("input[name='edit-zzje']").val();
                var beizhu = $(this).find("input[name='edit-beizhu']").val();
                var str = "<li class=\"rent-detail-item rent-detail-item-yj\">\n" +
                    "          <div>\n" +
                    "              <span>" + name + "</span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span>" + payDate + "</span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span> - </span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span> - </span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span> - </span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span> - </span>\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span class='real-zjje'>" + zzje + "</span>\n" +
                    "              " + fkfpStr + "\n" +
                    "          </div>\n" +
                    "          <div>\n" +
                    "              <span>" + beizhu + "</span>\n" +
                    "          </div>\n" +
                    "      </li>";
                $(this).remove();
                $(".container-rent-detail-list").append(str);
            } else {
                var yearCount = $(this).data("year");
                var startDate = "";
                if (addType != "change" && index == 1) {
                    startDate = $(this).find(".startDate").html();
                } else {
                    startDate = $(this).find(".startDate").val();
                }
                var endDate = "";
                if (addType == "change" || index < $(".container-rent-detail-list").find(".rent-detail-item").length - 1) {
                    endDate = $(this).find(".endDate").val();
                } else {
                    endDate = $(this).find(".endDate").html();
                }
                var payDate = $(this).find(".payDate").val();
                var znj = $(this).find("input[name='edit-znj']").val();
                if (!znj) {
                    dzl = 0;
                }
                var dzl = $(this).find("input[name='edit-dzl']").val();
                if (!dzl) {
                    dzl = " - ";
                } else {
                    dzl = dzl + "%";
                }
                var zk = "";
                zk = $(this).find("input[name='edit-zk']").val();
                if (zk == 10) {
                    zk = " - ";
                } else {
                    zk = zk + "折";
                }
                var zjdj = $(this).find("input[name='edit-zjdj']").val();
                var zzje = $(this).find("input[name='edit-zzje']").val();
                var beizhu = $(this).find("input[name='edit-beizhu']").val();

                var str = '<li class="rent-detail-item" data-year="' + yearCount + '">\n' +
                    '          <div>\n' +
                    '              <span>' + startDate + ' - ' + endDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + payDate + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + znj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + dzl + '</span>\n' +
                    '          </div>\n' +
                    // '          <div>\n' +
                    // '              <span>' + jcdj + '</span>\n' +
                    // '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zk + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + zjdj + '</span>\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span class="real-zjje">' + zzje + '</span>\n' +
                    '              ' + fkfpStr + '\n' +
                    '          </div>\n' +
                    '          <div>\n' +
                    '              <span>' + beizhu + '</span>\n' +
                    '          </div>\n' +
                    '      </li>';
                $(this).remove();
                $(".container-rent-detail-list").append(str);
            }
        });
        if (!!as && !!ae) {
            var str = '<li class="rent-detail-item-mzq">\n' +
                '          <div>\n' +
                '              <span>' + as + ' - ' + ae + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + '合同后免租期' + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(".container-rent-detail-list").append(str);
        }
    },
    // 保存修改后的物业账单
    savePropertyRentDetailTable: function () {

        $(".container-property-rent-detail-list").find(".property-rent-detail-item").each(function (index, elem) {
            var startDate = $(this).find(".startDate").val();
            var endDate = $(this).find(".endDate").val();
            var payDate = $(this).find(".payDate").val();
            var type = $(this).find("input[name='edit-type']").val();
            var id = $(this).find("input[name='edit-type']").data("id");
            var zzje = $(this).find("input[name='edit-zzje']").val();
            var fpzb = $(this).find("input[name='edit-fpzb']").val();
            var info = $(this).find("input[name='edit-info']").val();

            var str = '<li class="property-rent-detail-item">\n' +
                '          <div>\n' +
                '              <span>' + startDate + ' - ' + endDate + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + payDate + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span data-id="' + id + '">' + type + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + zzje + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + fpzb + '</span>\n' +
                '          </div>\n' +
                '          <div>\n' +
                '              <span>' + info + '</span>\n' +
                '          </div>\n' +
                '      </li>';
            $(this).remove();
            $(".container-property-rent-detail-list").append(str);
        });
    },
    // 水费收费方式-----抄表
    wSffsChange: function () {
        $(".w-sbds-list").empty();

        var ids = "";
        $(chooseItemArray).each(function (index) {
            ids += chooseItemArray[index].id + ",";
        });
        if (!!ids && ids.length > 0) {
            $.ajax({
                url: "/room/findHydropowerWaterByIds",
                data: {PROJECTID: ids},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        if (!!res.data && res.data.length > 0) {
                            for (var i = 0; i < res.data.length; i++) {
                                var IS_CARD = "";
                                if (res.data[i].IS_CARD == 1) {
                                    IS_CARD = "(插卡式)";
                                }

                                var bl = '';
                                if (res.data[i].BID.indexOf(",") > 0 ) {
                                    var pids = res.data[i].PROJECTID.split(",");
                                    var pnames = res.data[i].ROOM_NUM.split(",");
                                    var bids = res.data[i].BID.split(",");

                                    Array.prototype.distinct = function (){
                                        var arr = this,
                                            result = [],
                                            len = arr.length;
                                        arr.forEach(function(v, i ,arr){  //这里利用map，filter方法也可以实现
                                            var bool = arr.indexOf(v,i+1);  //从传入参数的下一个索引值开始寻找是否存在重复
                                            if(bool === -1){
                                                result.push(v);
                                            }
                                        });
                                        return result;
                                    };
                                    var pids = pids.distinct();
                                    var bids = bids.distinct();
                                    var pnames = pnames.distinct();

                                    for (var j = 0; j < bids.length; j++) {
                                        for  (var m = 0; m < pids.length; m++) {
                                            if (bids[j] == pids[m]) {
                                                bl += '<div style="width: 150px; margin-top: 10px;" class="layui-input-inline">\n' +
                                                    '    <input data-project="' + bids[j] + '" type="number" name="bl" placeholder="' + pnames[j] + '所占比例" autocomplete="off" class="layui-input">\n' +
                                                    '<span class="input-label-unit">%</span>' +
                                                    '  </div>\n';
                                            }
                                        }
                                    }
                                }

                                var str = '<div class="layui-inline data-bid" style="max-width: 400px; padding-bottom: 5px; border-bottom: 1px solid #e2e2e2;" data-rid="' + res.data[i].PROJECTID + '" data-bid="' + res.data[i].ID + '">\n' +
                                    '          <div style="width: 230px;" class="layui-input-inline">\n' +
                                    '              <span style="line-height: 28px;">' + res.data[i].CODE + IS_CARD + '</span>\n' +
                                    '          </div>\n' +
                                    '          <div style="clear: both; display: inline-grid;"><div style="width: 150px;" class="layui-input-inline">\n' +
                                    '              <input type="number" name="dqds" placeholder="当前读数" autocomplete="off" class="layui-input">\n' +
                                    '          </div>\n' +
                                    '          <div style="width: 150px; margin-top: 10px;" class="layui-input-inline">\n' +
                                    '              <input type="text" name="cbrq" placeholder="当前读数抄表日期" autocomplete="off" class="layui-input">\n' +
                                    '          </div>\n' +
                                    bl +
                                    '      </div></div>';
                                $(".w-sbds-list").append(str);
                            }
                        }
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
        }
        /*$("input[name='room']").each(function (index) {

            if ($(this).attr("data-wid") != "" && $(this).attr("data-wid") != "undefined" && $(this).attr("data-wid") != undefined) {

                var bid = $(this).attr("data-bid");
                var buildingPrice = init.initHydropower(bid);

                for (var i = 0; i < buildingPrice.length; i++) {
                    var str = '<p>' + $(this).attr("data-name") + '：' + buildingPrice[i].WATER_PRICE + '元/吨</p>';
                    if (!!buildingPrice[i].WATER_PRICE) {
                        $(".w-default-price").append(str);
                    }
                }

                var str = '<div class="init-read" data-roomid="' + $(this).attr("data-id") + '" data-hyid="' + $(this).attr("data-eid") + '">\n' +
                    '          <span>' + $(this).attr("data-name") + '</span>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <input type="number" name="dqds" placeholder="当前读数" autocomplete="off" class="layui-input">\n' +
                    '          </div>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <input type="text" name="cbrq" placeholder="当前读数抄表日期" autocomplete="off" class="layui-input">\n' +
                    '          </div>\n' +
                    '      </div>';
                $(".w-sffs-content").append(str);
            }
        });*/
        // 物业合同水电表抄表日期框初始化
        $("input[name='cbrq']").each(function () {
            laydate.render({
                elem: this, //指定元素
                btns: ['now', 'confirm']
            });
        });
        $(".sb-setting-class").show();
        $(".w-sfrq-content-gd").hide();
        $(".w-sfrq-content-cb").show();

        wtype = $(":radio[name='w-unit-price']:checked").val();
        var wsffs = $("select[name='w-sffs']").val();
        if (wtype == "1") {
            $(".w-default-price").show();
            $(".w-diy-price").hide();
        } else if (wtype == "0") {
            $(".w-default-price").hide();
            $(".w-diy-price").show();
        }
        if (wsffs == "3") {
            $(".w-default-price").hide();
            $(".w-diy-price").hide();
        }
    },
    // 电费收费方式-----抄表
    eSffsChange: function () {
        $(".e-dbds-list").empty();

        var ids = "";
        $(chooseItemArray).each(function (index) {
            ids += chooseItemArray[index].id + ",";
        });
        if (!!ids && ids.length > 0) {
            $.ajax({
                url: "/room/findHydropowerElectricByIds",
                data: {PROJECTID: ids},
                dataType: "json",
                type: "post",
                async: false,
                success: function (res) {
                    if (res.errcode === "0") {
                        if (!!res.data && res.data.length > 0) {
                            for (var i = 0; i < res.data.length; i++) {
                                var IS_CARD = "";
                                if (res.data[i].IS_CARD == 1) {
                                    IS_CARD = "(插卡式)";
                                }

                                var bl = '';
                                if (res.data[i].BID.indexOf(",") > 0 ) {
                                    var pids = res.data[i].PROJECTID.split(",");
                                    var pnames = res.data[i].ROOM_NUM.split(",");
                                    var bids = res.data[i].BID.split(",");

                                    Array.prototype.distinct = function (){
                                        var arr = this,
                                            result = [],
                                            len = arr.length;
                                        arr.forEach(function(v, i ,arr){  //这里利用map，filter方法也可以实现
                                            var bool = arr.indexOf(v,i+1);  //从传入参数的下一个索引值开始寻找是否存在重复
                                            if(bool === -1){
                                                result.push(v);
                                            }
                                        });
                                        return result;
                                    };
                                    var pids = pids.distinct();
                                    var bids = bids.distinct();
                                    var pnames = pnames.distinct();

                                    for (var j = 0; j < bids.length; j++) {
                                        for  (var m = 0; m < pids.length; m++) {
                                            if (bids[j] == pids[m]) {
                                                bl += '<div style="width: 150px; margin-top: 10px;" class="layui-input-inline">\n' +
                                                    '    <input data-project="' + bids[j] + '" type="number" name="bl" placeholder="' + pnames[j] + '所占比例" autocomplete="off" class="layui-input">\n' +
                                                    '<span class="input-label-unit">%</span>' +
                                                    '  </div>\n';
                                            }
                                        }
                                    }
                                }

                                var str = '<div class="layui-inline data-bid" style="max-width: 400px; padding-bottom: 5px; border-bottom: 1px solid #e2e2e2;" data-rid="' + res.data[i].PROJECTID + '" data-bid="' + res.data[i].ID + '">\n' +
                                    '          <div style="width: 230px;" class="layui-input-inline">\n' +
                                    '              <span style="line-height: 28px;">' + res.data[i].CODE + IS_CARD + '</span>\n' +
                                    '          </div>\n' +
                                    '          <div style="clear: both; display: inline-grid;"><div style="width: 150px;" class="layui-input-inline">\n' +
                                    '              <input type="number" name="dqds" placeholder="当前读数" autocomplete="off" class="layui-input">\n' +
                                    '          </div>\n' +
                                    '          <div style="width: 150px; margin-top: 10px;" class="layui-input-inline">\n' +
                                    '              <input type="text" name="cbrq" placeholder="当前读数抄表日期" autocomplete="off" class="layui-input">\n' +
                                    '          </div>\n' +
                                    bl +
                                    '      </div></div>';
                                $(".e-dbds-list").append(str);
                            }
                        }
                    } else if (res.errcode === "1") {
                        layer.msg(res.errmsg, function () {
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.error(XMLHttpRequest.status);
                    console.error(XMLHttpRequest.readyState);
                    console.error(textStatus);
                }
            });
        }
        /*$("input[name='room']").each(function () {
            if ($(this).attr("data-eid") != "" && $(this).attr("data-eid") != "undefined" && $(this).attr("data-eid") != undefined) {

                var bid = $(this).attr("data-bid");
                var buildingPrice = init.initHydropower(bid);

                for (var i = 0; i < buildingPrice.length; i++) {
                    var str = '<p>' + $(this).attr("data-name") + '：' + buildingPrice[i].ELETRIC_PRICE + '元/度</p>';
                    if (!!buildingPrice[i].ELETRIC_PRICE) {
                        $(".e-default-price").append(str);
                    }
                }

                var str = '<div class="init-read" data-roomid="' + $(this).attr("data-id") + '" data-hyid="' + $(this).attr("data-eid") + '">\n' +
                    '          <span>' + $(this).attr("data-name") + '</span>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <input type="number" name="dqds" placeholder="当前读数" autocomplete="off" class="layui-input">\n' +
                    '          </div>\n' +
                    '          <div class="layui-input-inline">\n' +
                    '              <input type="text" name="cbrq" placeholder="当前读数抄表日期" autocomplete="off" class="layui-input">\n' +
                    '          </div>\n' +
                    '      </div>';
                $(".e-sffs-content").append(str);
            }
        });*/
        // 物业合同水电表抄表日期框初始化
        $("input[name='cbrq']").each(function () {
            laydate.render({
                elem: this, //指定元素
                btns: ['now', 'confirm']
            });
        });
        $(".db-setting-class").show();
        $(".e-sfrq-content-gd").hide();
        $(".e-sfrq-content-cb").show();

        etype = $(":radio[name='e-unit-price']:checked").val();
        var esffs = $("select[name='e-sffs']").val();
        if (etype == "1") {
            $(".e-default-price").show();
            $(".e-diy-price").hide();
        } else if (etype == "0") {
            $(".e-default-price").hide();
            $(".e-diy-price").show();
        }
        if (esffs == "3") {
            $(".e-default-price").hide();
            $(".e-diy-price").hide();
        }
    },
    // 根据所选房间项目判断产权进而显不显示合同信息
    cqChange: function (type) {
        if (type == "0") {
            $(".property-contract-info").remove();
            $(".contractInfo").show();
            var str = '<div class="layui-form-item">\n' +
                '          <div class="layui-inline">\n' +
                '              <label class="layui-form-label">合同签订日期：</label>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" class="layui-input" id="contract-signing-date"\n' +
                '                         placeholder="yyyy-MM-dd">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                         aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div class="layui-inline">\n' +
                '              <label class="layui-form-label">合同计租日期：</label>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" class="layui-input" id="contract-rent-date"\n' +
                '                         placeholder="yyyy-MM-dd">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                         aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '          </div>\n' +
                '          <div class="layui-inline">\n' +
                '              <label class="layui-form-label">合同结束日期：</label>\n' +
                '              <div class="layui-input-inline">\n' +
                '                  <input type="text" class="layui-input" id="contract-finish-date"\n' +
                '                         placeholder="yyyy-MM-dd">\n' +
                '                  <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                         aria-hidden="true"></i></span>\n' +
                '              </div>\n' +
                '          </div>\n' +
                '      </div>';
            str += '<div class="layui-btn-group">\n' +
                '       <a class="layui-btn layui-btn-primary layui-btn-small"\n' +
                '          onclick="operate.showDiscount(1);">一年</a>\n' +
                '       <a class="layui-btn layui-btn-primary layui-btn-small"\n' +
                '          onclick="operate.showDiscount(3);">三年</a>\n' +
                '       <a class="layui-btn layui-btn-primary layui-btn-small"\n' +
                '          onclick="operate.showDiscount(5);">五年</a>\n' +
                '   </div>';
            $(".contract-setting-center").empty();
            $(".contract-setting-center").append(str);
            init.initContractDate(today, today, today);
        } else if (type == "1") {
            var str = '<div class="quote-contract-info property-contract-info">\n' +
                '           <div class="quote-title">\n' +
                '               <i class="fa fa-circle-o" aria-hidden="true"></i>\n' +
                '               <span style="margin-left: 12px; font-weight: 500; font-size: 16px; color: #1a2838;">合同信息</span>\n' +
                '           </div>\n' +
                '           <div class="contract-setting layui-row" style="bottom: none;">\n' +
                '               <div class="layui-col-md4 contract-setting-body">\n' +
                '                   <div class="layui-form-item">\n' +
                '                       <div class="layui-inline">\n' +
                '                           <label class="layui-form-label">合同签订日期：</label>\n' +
                '                           <div class="layui-input-inline">\n' +
                '                               <input type="text" class="layui-input" id="contract-signing-date"\n' +
                '                                      placeholder="yyyy-MM-dd">\n' +
                '                               <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                                      aria-hidden="true"></i></span>\n' +
                '                           </div>\n' +
                '                       </div>\n' +
                '                       <div class="layui-inline">\n' +
                '                           <label class="layui-form-label">合同计租日期：</label>\n' +
                '                           <div class="layui-input-inline">\n' +
                '                               <input type="text" class="layui-input" id="contract-rent-date"\n' +
                '                                      placeholder="yyyy-MM-dd">\n' +
                '                               <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                                      aria-hidden="true"></i></span>\n' +
                '                           </div>\n' +
                '                       </div>\n' +
                '                       <div class="layui-inline">\n' +
                '                           <label class="layui-form-label">合同结束日期：</label>\n' +
                '                           <div class="layui-input-inline">\n' +
                '                               <input type="text" class="layui-input" id="contract-finish-date"\n' +
                '                                      placeholder="yyyy-MM-dd">\n' +
                '                               <span class="input-label-unit-icon"><i class="fa fa-calendar"\n' +
                '                                                                      aria-hidden="true"></i></span>\n' +
                '                           </div>\n' +
                '                       </div>\n' +
                '                   </div>\n' +
                '               </div>\n' +
                '           </div>\n' +
                '           <div class="layui-clear"></div>\n' +
                '      </div>';
            $(".propertyInfo").empty();
            $(".propertyInfo").append(str);
            $(".contract-setting-center").empty();
            $(".contractInfo").hide();
            init.initContractDate(today, today, today);
            $(".submitBtn").removeClass("layui-btn-disabled");
        }
    },
    // 银行改变
    bankCodeChange: function (code) {
        if (code == 305 || code == 307) {
            change.setID(1);
        } else {
            change.setID(2);
        }
        if (code == 102 || code == 306) {
            change.setAccountProp(1);
        } else {
            change.setAccountProp(2);
        }
        if (code == 103 || code == 104) {
            change.setProvince(1);
        } else {
            change.setProvince(2);
        }
        switch (code) {
            case 102:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>默认单笔单日单卡5万额度，需特殊申请：单笔单日单卡5-99万，及实时通道。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>如需调高额度，可提交持卡人申请材料进行报备，最高可调至500万；</p>" +
                    "<p>摘要有两个中文字；</p>" +
                    "<p>工行限制以下卡段交易，622208181200070000至622208181200095999；</p>" +
                    "<p>工行对公代收需要进行报备受理及开户网点授权。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("商户简称");
                break;
            case 103:
                change.setAccountType(1);
                $(".daishou-box").find(".dbxe-content").html("<p>需特殊申请：单笔单卡5万，可累计。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>存折只上送15位账号，暂不受理福建地区卡交易。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日（部分T+1日内回盘）");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型填写其它费用（14900），摘要为：代理服务费\n" +
                    "业务类型填写租赁服务费（10702），摘要为：租赁服务费\n" +
                    "业务类型填写还贷（14901），摘要为：消费贷款\n" +
                    "业务类型填写货款（14902），摘要为：货款");
                break;
            case 104:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单卡单笔单日1万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>中行摘要可以在存折上打印，或到柜台打印电子回单。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("商户简称+业务类型");
                break;
            case 105:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单笔5000元，单日累计10000元（可做到5万元）；</p>" +
                    "<p>需特殊申请：单笔单卡单日只限借记卡：50万元。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>摘要有六、七个中文字。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日（部分T+1日内回盘）");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("商户简称+业务类型");
                break;
            case 301:
                change.setAccountType(1);
                $(".daishou-box").find(".dbxe-content").html("<p>需特殊申请：单笔单卡5万，可累计。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日（部分T+1日内回盘）");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型填写其它费用（14900），摘要为：代理服务费\n" +
                    "业务类型填写租赁服务费（10702），摘要为：租赁服务费\n" +
                    "业务类型填写还贷（14901），摘要为：消费贷款\n" +
                    "业务类型填写货款（14902），摘要为：货款");
                break;
            case 302:
                change.setAccountType(1);
                $(".daishou-box").find(".dbxe-content").html("<p>实时批量需特殊申请：单笔50万，日累计100万。</p>" +
                    "<p>实时交易首笔失败，次笔成功。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日（部分T+1日内回盘）");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型填写其它费用（14900），摘要为：代理服务费\n" +
                    "业务类型填写租赁服务费（10702），摘要为：租赁服务费\n" +
                    "业务类型填写还贷（14901），摘要为：消费贷款\n" +
                    "业务类型填写货款（14902），摘要为：货款");
                break;
            case 303:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单笔单卡500万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>摘要有四个中文字。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("商户简称+业务类型");
                break;
            case 304:
                change.setAccountType(1);
                $(".daishou-box").find(".dbxe-content").html("<p>单笔单日100万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日（部分T+1日内回盘）");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型填写其它费用（14900），摘要为：代理服务费\n" +
                    "业务类型填写租赁服务费（10702），摘要为：租赁服务费\n" +
                    "业务类型填写还贷（14901），摘要为：消费贷款\n" +
                    "业务类型填写货款（14902），摘要为：货款");
                break;
            case 305:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单卡单笔20万、单卡日限50万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("代收-业务类型");
                break;
            case 306:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单笔单卡500万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>广发银行23:00-08:00之内不接受交易。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("银联收付");
                break;
            case 307:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>单笔单卡5万，可累计。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型");
                break;
            case 308:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>批量单卡单笔：500万;</p>" +
                    "<p>需特殊申请：实时单卡单笔单日5万。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型");
                break;
            case 309:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>批量：500万；</p>" +
                    "<p>实时：单卡单笔5万，可累计。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>摘要有六、七个中文字。</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("批量交易：代理收取+业务类型；实时交易：保险费");
                break;
            case 310:
                change.setAccountType(1);
                $(".daishou-box").find(".dbxe-content").html("<p>单卡单笔单日5000元以内（含）。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("银联网络+商户简称");
                break;
            case 403:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p>需特殊申请：单笔单卡5万，可累计。</p>");
                $(".daishou-box").find(".dsbz-content").html("<p>摘要有二个中文字；</p>" +
                    "<p>批量交易当日晚20点之前提交交易于T日或T+1日回盘，当日晚20点之后提交交易于T+1日或T+2日回盘</p>");
                $(".daishou-box").find("input[name='HPSJ']").val("T日晚20点受理，有可能出现跨天回盘情况");
                $(".daishou-box").find("input[name='QSSJ']").val("T+1日");
                $(".daishou-box").find("textarea[name='ZY']").val("业务类型填写其它费用（14900），摘要为：代理服务费\n" +
                    "业务类型填写租赁服务费（10702），摘要为：租赁服务费\n" +
                    "业务类型填写还贷（14901），摘要为：消费贷款\n" +
                    "业务类型填写货款（14902），摘要为：货款");
                break;
            default:
                change.setAccountType(2);
                $(".daishou-box").find(".dbxe-content").html("<p></p>");
                $(".daishou-box").find(".dsbz-content").html("<p></p>");
                $(".daishou-box").find("input[name='HPSJ']").val("");
                $(".daishou-box").find("input[name='QSSJ']").val("");
                $(".daishou-box").find("textarea[name='ZY']").val("");
                break;
        }
    },
    // 省份改变
    provinceChange: function (code) {
        $(".daishou-box").find("select[name='CITY']").html('<option value="">请选择市</option>');
        for (var j = 0; j < region.length; j++) {
            if (code == region[j].name) {
                var reg = region[j].children;
                for (var i = 0; i < reg.length; i++) {
                    var str = '<option value="' + reg[i].name + '">' + reg[i].name + '</option>';
                    $(".daishou-box").find("select[name='CITY']").append(str);
                }
                break;
            }
        }
        form.render('select');
    },
    // 根据银行设置可以选择的账号类型
    setAccountType: function (type) {
        if (type == 1) {
            $(".daishou-box").find("input:radio[name='ACCOUNT_TYPE'][value='01']").attr("disabled", '');
            $(".daishou-box").find("input:radio[name='ACCOUNT_TYPE'][value='01']").removeAttr("checked");
            $(".daishou-box").find("input:radio[name='ACCOUNT_TYPE'][value='00']").prop("checked", true);
        } else if (type == 2) {
            $(".daishou-box").find("input:radio[name='ACCOUNT_TYPE'][value='01']").removeAttr("disabled");
        }
        form.render("radio");
    },
    // 根据银行设置可以选择的账号属性
    setAccountProp: function (type) {
        if (type == 1) {
            $(".daishou-box").find("input:radio[name='ACCOUNT_PROP'][value='1']").removeAttr("disabled");
        } else if (type == 2) {
            $(".daishou-box").find("input:radio[name='ACCOUNT_PROP'][value='1']").attr("disabled", '');
            $(".daishou-box").find("input:radio[name='ACCOUNT_PROP'][value='1']").removeAttr("checked");
            $(".daishou-box").find("input:radio[name='ACCOUNT_PROP'][value='0']").prop("checked", true);
        }
        form.render("radio");
    },
    // 根据银行设置省份是否必选
    setProvince: function (type) {
        if (type == 1) {
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".width10").html('*');
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".width10").addClass('layui-form-mid-red');
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".width10").removeClass('width10');
        } else if (type == 2) {
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".layui-form-mid-red").html('');
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".layui-form-mid-red").addClass('width10');
            $(".daishou-box").find("select[name='PROVINCE']").parent().parent().find(".layui-form-mid-red").removeClass('layui-form-mid-red');
        }
    },
    // 根据银行设置证件类型是否必填
    setID: function (type) {
        if (type == 1) {
            $(".daishou-box").find("select[name='ID_TYPE']").val('0');
            $(".daishou-box").find("select[name='ID_TYPE']").attr("disabled", '');
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".width10").html('*');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".width10").html('*');
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".width10").addClass('layui-form-mid-red');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".width10").addClass('layui-form-mid-red');
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".width10").removeClass('width10');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".width10").removeClass('width10');
        } else if (type == 2) {
            $(".daishou-box").find("select[name='ID_TYPE']").removeAttr("disabled");
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".layui-form-mid-red").html('');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".layui-form-mid-red").html('');
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".layui-form-mid-red").addClass('width10');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".layui-form-mid-red").addClass('width10');
            $(".daishou-box").find("select[name='ID_TYPE']").parent().parent().find(".layui-form-mid-red").removeClass('layui-form-mid-red');
            $(".daishou-box").find("input[name='CID']").parent().parent().find(".layui-form-mid-red").removeClass('layui-form-mid-red');
        }
        form.render("select");
    }
};
/**
 * 计算方法集合
 * 使用： calculate.function()
 * param: obj传this，调用该方法的对象
 *
 */
var calculate = {
    // 设置总面积
    setTotalArea: function () {
        var totalArea = 0;
        $(".room-area-single").each(function () {
            totalArea += Number($(this).html());
        });
        $("input[name='totalArea']").val(totalArea.toFixed(2));
    },
    // 返回总面积
    totalArea: function () {
        /*var totalArea = 0;
        $(".room-area-single").each(function () {
            totalArea += Number($(this).html());
        });
        $("input[name='totalArea']").val(totalArea.toFixed(2));*/
        return $("input[name='totalArea']").val();
    },
    // 计算押金的金额
    securityDeposit: function () {
        var totalArea = calculate.totalArea();  // 总面积
        var rentSinglePrice = $("input[name='rentSinglePrice']").val(); // 租金单价
        var securityDepositMonths = $("input[name='securityDepositMonths']").val();   // 押金押几个月
        return Number(totalArea) * Number(rentSinglePrice) * Number(securityDepositMonths) * 30;
    },
    // 返回月租金
    oneMonthPrice: function () {
        var totalArea = calculate.totalArea();  // 总面积
        var rentSinglePrice = $("input[name='rentSinglePrice']").val(); // 租金单价
        return Number(totalArea) * Number(rentSinglePrice);
    }
};

